ali-myousefi
ali-myousefi

Reputation: 872

Chrome [VM] files create event handler in every load

I use asp.net razor and I load part of page in a partial view by Jquery load function. Part of script in the partial view is a JavaScript event like this:

$("#FormId").on("submit", function () {
     //doSomeThing..
     //ajax request ..
     $("ContainerDivId").load("UrlToAction"); //load partial view in ajax success function
});

The problem is event create by every load and bind to another handler in another chrome VM file so handler function call several times by click on submit button.

enter image description here

I solved the problem by a flag variable but I know there is a clean solution. Where did I go wrong?

Upvotes: 1

Views: 320

Answers (1)

Barmar
Barmar

Reputation: 781058

Change your code that adds the event handler to remove the old one first:

$("#duplicateFacilityForm").off("submit").on("submit", function ...);

Upvotes: 1

Related Questions