0

I use AJAX to send some data to PHP for putting into MySQL after doing that, I want AJAX to do something like running another AJAX for me... I can put data into MySQL... but I can't do other AJAX or anything else like alert something or refresh the page...

here is JavaScript code

$.ajax({
    url: '/myFirstUrl',
    data: {data1: data1, data2: data2},
    type: 'post',
    dataType: 'json',
    success: function () {

then

alert('inserted');

Or

$.ajax({
    url: '/secondUrl',
    data: {data1: data1, data2: data2},
    type: 'post',
    dataType: 'json',
    success: function () {
}

Or

location.reload();

}


 });
Dharman
  • 30,962
  • 25
  • 85
  • 135
Bahram
  • 87
  • 1
  • 9
  • Sorry, but I can not imagine what are you talking about. Please tell us: when and how do you fire the first request and when and why want you the second one to be done? – Thomas Deutschländer Jul 20 '19 at 20:25
  • Do want to chain Ajax calls? Have a look at [*promises*](https://stackoverflow.com/questions/16026942/how-do-i-chain-three-asynchronous-calls-using-jquery-promises). – Paul Spiegel Jul 20 '19 at 20:28
  • 1
    You need to use the callback methods, like the one under "success". There you can fire a location.reload, which will be triggered, when the Ajax Request is completed. – Armin Jul 20 '19 at 20:30

1 Answers1

1

you can use Ajax complete method.Use the documentation Ajax complete. It's work only after the success so that's like your case, you can search in stackoverflow for more similar questions.

success: function(data)          
 {   
 },
complete: function (data) {
   //Do somting here 
 }
  • `complete()` in a jQuery ajax method will always run when the request is finished whether the response be success or failure, not only when it is success. – Michael Cacciano Jul 21 '19 at 05:01
  • Yes, that's true I din't mansion that. There is documentation link so anybody can check it out. He can create another function and call it in success like success: successFunction, but I don't it's the case probably he has error, and he is not handling that has the check is return. – Cafer Yükseloğlu Jul 21 '19 at 09:03