tags:

views:

36

answers:

1

Hello, I was wondering if there's a simple way with Jquery to do something while the PHP process called by the forms gives a respond.

PS: I'm well aware of the ajax functions to send POST data and on success do something.

I'll explain I have a form on 1.php page that points to 2.php (just a script) that either redirects to the 1.php if something went wrong or to page 3.php if it's ok.

Want I wanna do with Jquery is show just a message with a gif loader (append a text below the submit button) while this submit process finishes (it could take up 10 secs since it resizes images). I'm asking a simple way because I don't want to pass each POST data through AJAX or validate data because this is all handled by the PHP page (2.php) by redirecting to pages.

I was able to do it the problem is that once you submit, since it returns true, everything on the original page stops. For example I put an animation to text "Processing, please wait..." with a gif which respectively won't continue through the all waiting time and won't show because if not saved in the cache some other time previously the submit will stop that process to download it, even if I preload it it won't animate for the same reason.

Basically what I need is to pass all the POST data through jquery ajax on submit (returning false to allow the new next to show!) and "let the process" continue on whatever response.

Thank you.

A: 

You can use a synchronous call instead of async for the jquery 'ajax' post, which will not return until the server's done processing. As part of the submit handler, pop up your "please wait, processing" message, and take it down once the response is received.

Marc B
I took a look at that thread and it seems to me that I still have to pass parameters through POST in ajax?
Sandro Antonucci
Yes, but that's how it would have to be. You could do an onsubmit handler to pop up the "please wait" message, but there's no guarantee it would be seen. After all, you've clicked submit, which means you've started navigating to a new page. The AJAX method at least guarantees you'll still be on the same page when the request completes.
Marc B
Thank you for the explanation
Sandro Antonucci