php - JQuery AJAX: Form submits twice -
in form i'm using ajax submit form. when click submit button executes method twice. can guide me find out problem
$("form#dealform").submit(function(event){ //disable default form submission event.preventdefault(); var $form = $(event.target); //grab form data var formdata = new formdata($(this)[0]); $.ajax({ url: $form.attr('action'), type: 'post', data: formdata, async: false, cache: false, contenttype: false, processdata: false, success: function (returndata) { alert(returndata.message); } }); return false; });
html:
<form name="dealform" id="dealform" action="<?php echo base_url(); ?>deals/update_deal/" method="post" enctype="multipart/form-data">
try this, if works, form hooked "submit" twice:
$("form#dealform").unbind('submit').submit( ...
this unbind submit, bind action. fix if form bound submit. 1 of many possibilities, due calling script twice or perhaps validation plugin binding submit event separately.
note: can potentially unhook validation plugin, or other scripts bound submit.
if fix problem you, should investigate why happening. fix that, , remove unbind
command. may fix problem, may cause more problems later. (aka: use debugging)
Comments
Post a Comment