1

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

Marc
  • 9,217
  • 21
  • 67
  • 90
  • Possible Duplicate of: http://stackoverflow.com/questions/446594/kill-ajax-requests-using-javascript-using-jquery – BenOfTheNorth Mar 19 '12 at 13:49
  • 1
    Can you be more specific? How do you want to kill it? What exactely do you mean by "killing"? – Rob W Mar 19 '12 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 Mar 19 '12 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 Mar 19 '12 at 13:52
  • Ben, in the future I will definetely give it a var in order to be abble to use the abort() method. But currently my ajax call has no var so I have to use another technic. Hope there is one... – Marc Mar 19 '12 at 13:53
  • 1
    The 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 progress – BenOfTheNorth Mar 19 '12 at 13:55
  • Are you 100% sure that there is no way? – Marc Mar 19 '12 at 13:57
  • Not 100%, but I can't see how you can interact with something that doesn't exist as some form of object or variable... – BenOfTheNorth Mar 19 '12 at 13:59

2 Answers2

1

To kill a running php script : restart the web server.

dweeves
  • 5,525
  • 22
  • 28
0

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)

dweeves
  • 5,525
  • 22
  • 28
  • 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... – Marc Mar 19 '12 at 13:55
  • 1
    in that case, restart the web server ! – dweeves Mar 19 '12 at 13:57
  • Put it as answer instead of what you suggested in the first place. An accepted answer is waiting for you... – Marc Mar 19 '12 at 14:03