I have a button on my page. When clicked it triggers an ajax call using the ajax method of jquery. The php script runs loops that insert data into my db. My problem that I want to kill that script from running but I don't know how to do. Hope someone can help. Thank you in advance. Cheers. Marc
8
-
Possible Duplicate of: stackoverflow.com/questions/446594/…BenOfTheNorth– BenOfTheNorth2012-03-19 13:49:11 +00:00Commented Mar 19, 2012 at 13:49
-
1Can you be more specific? How do you want to kill it? What exactely do you mean by "killing"?Rob W– Rob W2012-03-19 13:49:47 +00:00Commented Mar 19, 2012 at 13:49
-
Hello Ben. The thing is I did not gave a variable to my ajax call. So I can't use the technic your are suggesting. But I still need to kill the script that has been launched...Marc– Marc2012-03-19 13:50:52 +00:00Commented Mar 19, 2012 at 13:50
-
Hello Rob. By killing I mean stop it. The thing is my loop runs ten thousand of times. It is currently looping and I need to stop it. Hope I am clear...Marc– Marc2012-03-19 13:52:04 +00:00Commented Mar 19, 2012 at 13:52
-
1The problem is if you don't assign the call to a variable, then you'll have no simple way of interacting with it once it's in progressBenOfTheNorth– BenOfTheNorth2012-03-19 13:55:28 +00:00Commented Mar 19, 2012 at 13:55
|
Show 3 more comments
2 Answers
I would recommend:
in your looping script,at each loop, test for a session variable or a persisted value of any type (file, db) that would store a cancel flag. if this flag is set,break the loop this would abort the processing.
create another script (cancel.php) for example, that will set this cancel flag in the storage (session,file or db). this cancel script will be called via your ajax request.(of course , if you used session to store the cancel flag, don't forget to pass the same sessionid than your looping script as parameter of your ajax request)
3 Comments
Marc
Hello dweeves. Thanks for the reply. As mentionne, in the furutre I will put my ajax call in var so I can use the jquery abort() method. But now it is too late. The script is currently under execution and I need to find a way to stop it...
dweeves
in that case, restart the web server !
Marc
Put it as answer instead of what you suggested in the first place. An accepted answer is waiting for you...