Abort a previous running Ajax request [duplicate]


Is it possible to abort a previously-running Ajax request?

var xhr = $.ajax({
    type: "POST",
    url: "some.php",
    data: "name=John&location=Boston",
    success: function(msg){
       alert( "Data Saved: " + msg );
    }
});

try something like this

        $(document).ready(function(){
            var xhr; // global object

            function your_function() {
                if(xhr && xhr.readystate != 4){
                    xhr.abort();
                }

                xhr = $.ajax({
                    type: "POST",
                    url: "some.php",
                    data: "name=John&location=Boston",
                    success: function(msg){
                       alert( "Data Saved: " + msg );
                    }
                });
            }
        });