javascript - Execute $.ajax when HTML form submitted -
i want call $.ajax
when html form submitted. using .submit()
determine when form submitted. $.ajax
, when placed within .submit()
function, not executing.
however, when not within .submit()
function, $.ajax
executes perfectly.
here form:
<form id="searchform"> <input type="text" id="search"> <input type="submit" value="submit"> </form>
and here jquery:
baseurl = 'http://...'; $("#searchform").submit(function() { $.ajax({ type: 'get', url: baseurl, datatype: 'xml', success: function(xml){ // code here } }); });
simply need prevent default browser submit process.
a submit handler not override default process, intercepts , allows whatever need before submits ... or in case gets prevented
$("#searchform").submit(function(event) { event.preventdefault(); // ajax here });
Comments
Post a Comment