Im having a problem with my ASP.NET MVC project.
In my project, the user navigate between pages with tabs, every click on tab calls in ajax request to partial view and priniting the relevant HTML.
The problem happens when the partial view contains , for example:
<script src="bla.js" type='text/javascript'></script>
First of all, after I loaded the partial view, I cant find the script tag in the page source (or Inspect Elements in chrome). I dont know what the browser does with that script but the second problem, that every time its loaded again and again.
For example, if I have this event listener in my script file:
$("#button").live("click", function() { console.log("sdf") })
this method will happens again and again due the times the user navigates to this page. If its his second time, the event listener will call twice.
I hope you understand my complicated problem.
tnx!
.live
has been depreciated - use.on
) – Stephen Muecke Feb 27 at 10:51.on
- e.g.$(document).on('click', '#button', function() { ...
(but you should ideally replacedocument
with the closest ancestor that exists in the main view when the view is first rendered) – Stephen Muecke Feb 27 at 11:13