Cancel AJAX request

I have an AJAX request that takes data from a remote file and displays in a div on the page. AJAX is called, and the data div is displayed when the user hovers over the link and disappears when the mouse moves out of the link. The drive displays immediately, but when the mouse moves, there is about a 5 second delay between moving the mouse and hiding the div.

I assume it has something to do with the AJAX request blocking the hide function, because when I delete the AJAX request, the div is immediately hidden.

Is there something I could do to interrupt, kill, or ignore AJAX when the mouse is removed from the link and just hide the div no matter what?

Here is the code that I still have:

$(function(){

var showPopup = function(){
    $.ajax({
        type: "GET",
        url: "/process.cfm",
        data: "id=" + 1,
        success: function(data){
            $(".profilePopup").html(data);

            if ($(data).find(".profileResult").length) {
                var text = $(data).find(".profileResult").html();
                $(".profilePopup").html(text);
            }
        }
    });

    $(".profilePopup").show();
}

var hidePopup = function(){
    $(".profilePopup").hide();
}

$("#username").mouseover(showPopup);
$("#username").mouseout(hidePopup);
});
+3
source share
3

:

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

    //kill the request
    xhr.abort()
+3

ajax, jxhr:

http://api.jquery.com/jQuery.ajax/#jqXHR

- :

var jxhr_object = $.ajax({
    url: "some.php",    
    success: function(){
       do something
    }
});

//kill the request
jxhr_object.abort()
0
var xhr = $.ajax({
    type: "GET",
    url: "/process.cfm",
    async: true,
    data: "your data",

    success: function(msg){
       alert( "Data Saved: " + msg );
    }
});

//kill the request
xhr.abort()

This will not make your browser frozen.

async: true,

0
source

All Articles