检测AJAX请求

On my website I have mouse over and mouse out events set up on an HTML table. These events trigger ajax requests, and perform certain actions etc. However, i want to be able to not trigger a second request if one is already running. So, is there away to detect these requests, and therefore avoid a second. Incidentally Im using the jQuery $.ajax() if it helps at all.

Thanks in advance

Chris

For this suppose I'd use ajaxStart() and ajaxStop() which would change specific variable ajaxRunning which could be checked before sending the request (maybe in ajaxStart() directly?)

Set global or local static variable to true when first ajax is about to trigger, than add if before triggering the second one ;) Than after one request is finished, set this variable to false

I'd try something simple like:

var requestMade = false;

function yourAjaxFunction(){
    if(!requestMade)
    {
        requestmade = true;
        $.ajax({
            url: "page",
            success: function(){
                requestMade = false;
            }
            error: function(){
                requestMade = false;
            }
        });
    }
}

You can use the success: and error: settings to change the variable back to false.

I have never used the error so you may have to include some other things in it, but this is the general idea.