Javascript 暂停鼠标悬停/单击,直到完成$.get

Javascript 暂停鼠标悬停/单击,直到完成$.get,javascript,jquery,mouseevent,Javascript,Jquery,Mouseevent,在我的客户端页面上,每次用户单击某个内容时,我都希望执行我的函数。函数将此元素标记名发送到数据库。要避免覆盖客户端页面,请单击我使用的事件处理程序mousedown。我的想法是: jQuery('body').on('mousedown', function(event){ var that = event.target, thatTag = event.target.nodeName; jQuery.get( "http://example.

在我的客户端页面上,每次用户单击某个内容时,我都希望执行我的函数。函数将此元素标记名发送到数据库。要避免覆盖客户端页面,请单击我使用的事件处理程序
mousedown
。我的想法是:

jQuery('body').on('mousedown', function(event){
    var that = event.target,
        thatTag = event.target.nodeName;

    jQuery.get( 
        "http://example.com",
        { parameter: thatTag },
        function() {
            //It hasn't time to execute, because mouseup is auto executed and click action change location (if I click anchor)
        }
    );
});
那么,是否有任何选项可以暂停/阻止
mouseup
/
单击
,直到我的GET操作完成?

您需要在第一次执行
mousedown
处理程序时使用它解除绑定,然后在
.GET
函数完成时再次绑定:

$(function() {
    // On page load, bind the first instance of the event
    $("body").on("mousedown", handleMouseDown);
});

function handleMouseDown(event) {
    // Detach the event so that is isn't handled again until the .get finishes
    $("body").off("mousedown", handleMouseDown);
    var that = event.target,
        thatTag = event.target.nodeName;

    jQuery.get( 
        "http://example.com",
        { parameter: thatTag },
        function() {
            // Re-attach the event now that the .get has finished
            $("body").on("mousedown", handleMouseDown);
        }
    );
}

你必须继续在$中执行你的函数。获取回调,不要发明轮子,也许我解释错了。我的GET操作没有时间执行。我只想暂停鼠标点击,直到完成。之后,我希望mouseup/click back执行正常的客户端操作。您可以将此代码放在一个单独的函数中,并首先在以前编写的click事件处理程序函数中调用该函数