I have a form my_form
which needs to be refreshed (e.g. changing some elements in the form) via jquery every time the user change some data. In order to know what to change, an AJAX call needs to be executed
$('#my_form').change(function() {
...execute an ajax call and change the form via jquery
});
The problems arise when a user types something in a textbox and then click on the submit button (or press enter): both the change() event and the submission are triggered at the same time and the result is an "out of memory" error which prevents the form to be submitted.
I know this is a typical problem and the typical solution is to avoid using the classic submit button and to control the submit via jquery when the ajax call finishes. The problem here is that I don't want to submit the form every time the ajax call is executed (only when the user actually submits) AND I don't want to execute again the ajax call when the user submits the form.
The perfect solution would be: after the submission, wait until all the ajax calls are over and then submit. I think this is not possible unless you check ajaxStop
inside a loop, which I don't think it's a safe solution. Is there any other way?
Another solution would be to just submit the form despite the fact there is an AJAX call going on, in fact this wouldn't affect the user experience. How can I do it?
EDIT: I've found what the real issue is: in order to show a loader when ajax calls are in execution, I implemented the solution I've found here How can I create a "Please Wait, Loading..." animation using jQuery? (accepted answer).
For some reason, the modal
element prevents the submission of the form when is not hidden (i.e. when an ajax call is in execution); if I decrease the height of the element from 100% to 60% (I've guessed any value which makes the element not covering the submit button would be ok but I am not sure if it is a coincidence) it works.
Can anyone explain me what actually happens and how can I continue using that solution safely? Thanks.