ajax - jQuery Forms ajaxsubmit refreshes before result returns, but during debug, result displayed briefly then page refreshes(not wanted) -
apache on windows 7.
i want submit form perl cgi save data in mysql, returning json results (no "location" returns!). if don't put js break point in, page refreshes before response received. if breakpoint it, response received. results posted briefly, page refreshes, don't want happen!
standard form, no file upload
ajaxsubmit options:
var formapplyoptions = { url: "/cgi-bin/saveapplicant.cgi", beforesubmit: formvalidate, datatype: "json", target: "#applyresponse", success: showreceivedapplicant, error: showerror };
form submit button function:
$('#formdata').submit(function(e) { e.preventdefault(); e.stoppropagation(); alert("el oh!"); $('#formdata').ajaxsubmit(formapplyoptions); })
showerror:
function showerror(xhr, ajaxoptions, thrownerror) { //showresponse(responsetext, statustext, xhr, $form); $('div#errormsg').text("responsetext: " + xhr.responsetext + ", textstatus: " + xhr.statustext + ", errorthrown: " + thrownerror); $('div#error , form#formdata').addclass("error"); }
showreceivedapplicant:
function showreceivedapplicant(data, statustext, xhr, $form) { if (data.error) { // script returned data error $('div#error').text("data.error: " + data.error + ",\n" + 'status: ' + statustext); $('div#error, form#formdata').addclass("error"); } // if else if (data.success) { $('#applyresponse').append(data.success); $('#formdata').hide(); $('#received').show(); } //else }
formvalidate:
function formvalidate(formdata, jqform, options) { return $('#formdata').valid(); }
one thing did notice in tracing: seems responses being handled functions, when used non-minified version of jquery, jquery.js code runs right before refresh around 8605:
complete( xhrsuccessstatus[ xhr.status ] || xhr.status, xhr.statustext, // support: ie9 // accessing binary-data responsetext throws exception // (#11426) typeof xhr.responsetext === "string" ? { text: xhr.responsetext } : undefined, xhr.getallresponseheaders() <----- );
also @ 8278 jquery completes deferred callbacks(i think?)
after section of code, page refreshes. haven't been able figure out.
i know it's silly or stupid, after 2 days of staring @ code, it's time fresh eyes.
any appreciated!
Comments
Post a Comment