Andy
Andy

Reputation: 137

Jquery Ajax - Alert firing twice

The code below is triggered on a click of a button and having followed the request through, it is only being triggered once. Also, having stepped through, the code is only triggered once, however, the alerts show twice. Any suggestions for why?

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

Upvotes: 0

Views: 157

Answers (1)

rongsir
rongsir

Reputation: 19

How did you bind the click event to the button? Or did you bind the same event multiple times?

Is it like this:

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

Upvotes: 1

Related Questions