0

After page fully loaded, i make ajax request to an action.

While waiting for response from action (it takes 2 or 3 seconds), if user clicks on other link, i want to abort previous request and kill mysql process at once.

How can i do this?

I tried to do like this

var xhr = $.ajax({
/*
params
*/
});

//before unload page 
xhr.abort();

but i think, that it will not kill sql process.

1 Answers1

0

Make a named ajax. Here is ajx is named

var formData = {};//Your data for post
var ajx = $.ajax({
    type: "POST",// Http verbs
    url: "filename.php",// file to request
    data: formData,
    success: function(response){
        console.log("ajax completed");
        console.log(response);
    }
});

Stop ajax request by clicking button

$( "#button_id" ).click(function() {
    ajx.abort();
});
Niklesh Raut
  • 34,013
  • 16
  • 75
  • 109