jquery - Form still submitting with preventDefault and return false -
jquery - Form still submitting with preventDefault and return false -
i'm using next code submit form ajax:
<script> $('#subscribeline #subscribe').click(function(){ $('#subscribeline').html("<form id='subscribeform'><input type='email' name='email' id='email' value='' placeholder='enter email'><input type='submit' name='submit' id='submit' value='ok'></form>"); }); $(document).on('submit','#subscribeform', function(){ var postdata = $(this).serializearray(); $.ajax( { url : "insertsubscriber.php", type: "post", info : postdata, success:function(data, textstatus, jqxhr) { alert('ok'); }, error: function(jqxhr, textstatus, errorthrown) { alert('false'); } }); e.preventdefault(); homecoming false; }); </script> now thing part of page code loaded ajax. #subscribeform not exist on page load i've added script on secondpage.php , not index.php maintain things cleaner , organized.
the whole thing works (i alert box 'ok' or 'false') except ends submitting form despite preventdefault , homecoming false.
you missing 'e'
change this
$(document).on('submit','#subscribeform', function(){ with this
$(document).on('submit','#subscribeform', function(e){ jquery ajax forms
Comments
Post a Comment