intercept form submit with jQuery
Solution 1:
You can't return out of a callback to an asynchronous method(such as ajax). Instead, prevent the submit all together, then submit it when you are ready.
$("#methodForm").submit(function(e){
e.preventDefault();
var form = this;
checkIndex('upload/segments.gen').done(function() {
form.submit(); // submit bypassing the jQuery bound event
}).fail(function () {
alert("No index present!");
});
});
Solution 2:
It does'nt really work like that, checkIndex is asynchronous, so by the time it returns anything, the form is submitted, and the return statements are in a different scope as well, try something more like this:
$("#methodForm").submit(function(e){
e.preventDefault(); //prevent submit
var self = this;
checkIndex('upload/segments.gen').done(function() {
self.submit(); //submit if ajax OK
}).fail(function () {
alert("No index present!");
});
});