javascript - submitting form with PJAX -
im using pjax in web project, , when submit form, pjax handling it, related stuff coming in , replacing in pjax container, after default action happening- form getting submitted in traditional way , entire page loading again
form html here
<form class="form_class"><input type="text" name="search" id="search_query" class="basic_input" value="" /><button onclick="this.form.submit();" >find</button></form>
here pjax code form invoking
$(document).on('submit', '.form_class', function(event) { $.pjax.submit(event, '#container_id'); });
it works- the default form submission happens, want pjax way, dont want complete page reload(the traditional submission)
just use event object cancel default submission behavior:
$(document).on('submit', '.form_class', function(event) { event.preventdefault(); // stop default submit behavior $.pjax.submit(event, '#container_id'); });
if not work perhaps cancelling late. try:
$(document.body).on('submit', '.form_class', function(event) { event.preventdefault(); // stop default submit behavior when bubbles <body> $.pjax.submit(event, '#container_id'); });
Comments
Post a Comment