I want to stop the actions that are called by the jQuery.ajax method on the server side.
I can stop the Ajax request using $.ajax.abort() method on
Here is an example Backend:
[HttpGet]
public List Get(){
var gotResult = false;
var result = new List();
var tokenSource2 = new CancellationTokenSource();
CancellationToken ct = tokenSource2.Token;
Task.Factory.StartNew(() =>
{
// Do something with cancelation token to break current operation
result = SomeWhere.GetSomethingReallySlow();
gotResult = true;
}, ct);
while (!gotResult)
{
// When you call abort Response.IsClientConnected will = false
if (!Response.IsClientConnected)
{
tokenSource2.Cancel();
return result;
}
Thread.Sleep(100);
}
return result;
}
Javascript:
var promise = $.post("/Somewhere")
setTimeout(function(){promise.abort()}, 1000)
Hope I'm not to late.