Reputation: 167
I'm not sure if this is even possible or not, and I can't quite figure out how to actually do it, if possible at all.
What I'd like to do is have a list of checkboxes get submitted to an .ajax() call. That .ajax() call passes the information to PHP for processing (and in this case it will be sending e-mails to each one of those IDs selected).
However, I don't want the page (or the .ajax() call for that matter) to wait for the PHP script to finish running. Basically I want it to hand off the data and move on (and display a .dialog() box, etc., etc.)
Here's the trick though: I do want some type of feedback from the PHP script. When it's done, I want it to return data to the user, possibly by displaying a bar at the top of the page (much like what StackOverflow does when you have system messages, they show up at the top of the page regardless of where you are on the site.)
The first part, having a list of checkboxes displayed is done. I'm as far ahead as determining which ones are checked and collect that data. Now I need to figure out how to pass it to the .ajax() call in such a way that PHP can use it to scan a database to collect the various e-mails and start sending messages out. Not quite sure how to pass the data. It seems silly to create a dataString that consists of id1=XXX&id2=XXX&id3=XXX-and_so_forth.
I'm open for suggestions here.
[Edit] Anyone have any suggestions for the part I made bold above?
Upvotes: 1
Views: 5635
Reputation: 1690
If you are making calls to a .php script with AJAX (xmlHttpReq) and use flush, this will send data to your script HOWEVER it will not set the xmlHttpReq.readyState to 4 -- which is a requirement to use the information sent (Firefox does however allow you to use the responseText property with a readyState == 3 but IE will throw an error).
I got this from PHP.net when reading up on the flush()
- http://www.php.net/manual/en/function.flush.php
Basically this means that you can have a process started by an ajax call and have it return some value for example echo "hello";
but not have the readystate set to 4. So if you are clever about it you can manipulate your responses from your PHP script like for instance in a while loop with a timer.
Upvotes: 0
Reputation: 8452
default behavior for the Ajax Request is that they are asynchronous and that implies that the code run normally and don't wait the return of the AJAX call.
Example:
$.ajax({
url: "...",
data: "<checkboxes>",
success: function(data, xhr, status) {
// Code to add your banner when AJAX finished
}
});
// Inline code to execute whitout wait the end of $.ajax
Upvotes: 4
Reputation: 15835
THen you can go a head and use asyncronous ajax call , whatever logic you keep inside the success method of ajax can be moved out.
MakeAjaxCall() don't write anything inside the success method.
Write all your logic after you makeAjaxCall() ,so that both happens in parallel.
makeAjaxCall() , instantiates the process doyourlogicInParallel()...here
Upvotes: 0