Jquery Ajax - 两次警报射击

时间:2014-01-25 15:21:21

标签: c# jquery .net ajax json

下面的代码是通过点击按钮触发并跟随请求,只触发一次。此外,通过步骤,代码只触发一次,但警报显示两次。有什么建议吗?

$.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...
                }
            });

1 个答案:

答案 0 :(得分:1)

你是如何将点击事件绑定到按钮的?或者您多次绑定同一事件?

是这样的:

$("#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;
})