C# jqueryajax-警报触发两次

C# jqueryajax-警报触发两次,c#,jquery,.net,ajax,json,C#,Jquery,.net,Ajax,Json,下面的代码在点击一个按钮后被触发,在请求完成后,它只被触发一次。此外,通过后,代码仅触发一次,但警报显示两次。对原因有什么建议吗 $.ajax({ url: '@ConfigurationManager.AppSettings["AppDirectory"]/OperatorApplication/PafSearch/' + pafPostcode.val(), type: 'POST', succe

下面的代码在点击一个按钮后被触发,在请求完成后,它只被触发一次。此外,通过后,代码仅触发一次,但警报显示两次。对原因有什么建议吗

$.ajax({
                url: '@ConfigurationManager.AppSettings["AppDirectory"]/OperatorApplication/PafSearch/' + pafPostcode.val(),
                type: 'POST',
                success: function (response) {
                    addressList.empty();
                    addressSelection.hide();

                    if (response == null) {

                        alert("No addresses found for the postcode provided.\n\nPlease enter your address manually");

                    }                        
        //other processes removed...
                }
            });

如何将单击事件绑定到按钮?还是多次绑定同一事件

是这样的吗?

$("#targetButton").on("click", function(){
    $.ajax({
        url: '@ConfigurationManager.AppSettings["AppDirectory"]/OperatorApplication/PafSearch/' + pafPostcode.val(),
        type: 'POST',
        success: function (response) {
            addressList.empty();
            addressSelection.hide();
            if (response == null) {
                alert("No addresses found for the postcode provided.\n\nPlease enter your address manually");
            }
            //other processes removed...
        }
    });
    return false;
})

您确定请求只发送一次吗?您可以使用浏览器检查工具(firebug等)检查请求发送的次数。ajax请求可能从代码的另一部分发送了两次。您可以在$.ajax之前放置一个警报,以检查它是否被调用了两次。