The following code snippet explains a situation:-
function submitHandler(form) {
return x(form) && y(form);
}
x is an external function which validates the form. It returns false if form is not validated and if validated it submits the form.
y is a function, which should be called only if form is validated. It makes an AJAX call, JSONP type. JSONP ajax calls can only be async.
Y internally submits the form after getting the response. y will always return false.
I'm not sure what x does exactly but I can confirm y is called but AJAX call inside it is cancelled.
When I create a break-point and run in firebug debug mode, the AJAX call is successful. Thus, I think creating a delay can solve the problem.
Is there any way to create a delay after the AJAX call?
Update:
The function y:-
function y(jsonStr) {
jQuery.ajax({
url: url,
contentType: 'application/json',
dataType: 'jsonp',
data: {
jsonInfo: jsonStr,
jsonpCallback: 'submitForm'
}
});
}
update 2:
The function x (edited)
function x(form) {
clearError();
var submitButton = null;
var allowSubmit = true;
// Some code
for ( var i = 0; i < form.elements.length; i++) {
var fld = form.elements[i];
if (!validateField(fld)) {
allowSubmit = false;
}
}
if (allowSubmit) {
if (!pageSubmitted) {
pageSubmitted = true;
// some code
form.submit();
if (submitButton != null) {
submitButton.disabled = true;
submitButton.value = getPleaseWaitMessage();
}
} else {
allowSubmit = false;
}
}
// Some code
return allowSubmit;
}