Codechef4u is a community for computer professionals,by computer professionals,just like you; who loves sharing and helping each others,Join them
Share your post

Answers


The jquery ajax method returns here ajaxRequest (a XMLHttpRequest) object, then this object with abort() method used to abort request. 

Note:

The XMLHttpRequest.abort() method aborts the request if it has already been sent. When a request is aborted, its readyState is changed to XMLHttpRequest.UNSENT (0) and the request's status code is set to 0.

Code example

In following code sample ajax post request used to remove user, to kill or abort request used abort() method at end.

//ajax request 
        var ajaxRequest = $.ajax({
            type: "POST",
           //MVC post call 
            url: '@Url.Action("RemoveUser","User")',
            data: { 'userId': userID },
            success: function (msg) {
                console.log("User deleted: " + msg);
            }
        });
 
 //kill the ajax request
 ajaxRequest.abort() 


That will abort the Ajax call, but on the Controller side what's happening?

If the controller is performing some long run calculation, is it possible to notify the controller to stop it since it's no longer needed?


I think you can use following in your requirement 

this.Response.IsClientConnected

For more details check this stack overflow thread 

https://stackoverflow.com/questions/8914728/how-do-you-cancel-an-ajax-long-running-mvc-action-client-side-in-javascript 

Share your answer


Share as a guest

Please subscribe me to the CodeChef4U.

By creating your new answer, you agree to the privacy policy and terms of service.