Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a button click in javacript file through which i am making a ajax call.

strange is that, when i am running application through localhost, it working fine. But when i publish it, then try to run, this button event fired variable number of times, sometimes twice sometime thrice.But mostly twice. In button event i am giving a alert as validation. Moreover,this button click event come in document.ready function.

The code snippet is:

C#
$("#btnUpdate").click(function () {
    if ($("#drpstatusEdit option:selected").text() == 'Closed') {
        var OffshoreResourceIds = '';
        $('#drpOffshoreUsersEdit :selected').each(function (i, selected) {
            OffshoreResourceIds = OffshoreResourceIds + ',' + $(selected).val();
        });

        if ($("#txtTicketDesc").val() == '')
            alert('description cannot be blank');
        else searchUserWithoutCriterion();
    }
    else {
        updateTickets();

    }
    getTicketCount();
});

function updateTickets() {
    //some code with alert
    alert("something");
}



How to make this to get fired only once as it working fine when running through localhost.(i dont want button to unbind).
Posted
Updated 4-Feb-15 19:45pm
v2
Comments
[no name] 12-Feb-15 4:51am    
Can you please tell me which error you got in browser console ?

1 solution

Is you're button actually a button?
Or some nested HTML?
Try this;

JavaScript
$("#btnUpdate").click(function (evt) {
   evt.stopPropagation();
   evt.preventDefault();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900