Run ajax scripts on page when navigating with ajax?

Posted by Oskar Kjellin on Stack Overflow See other posts from Stack Overflow or by Oskar Kjellin
Published on 2010-05-29T20:15:42Z Indexed on 2010/05/30 8:42 UTC
Read the original article Hit count: 419

Filed under:
|
|

I got a bit of an issue in my ASP.NET MVC project.

I have a chat div in the bottom right corner (like facebook), and of course I do not want this to reload when navigating to all my navigation is ajax.

The problem I am facing is that I use the following code on the top of the view page:

<script type="text/javascript">
$(document).ready(function() {
  $('#divTS').hide();
    $('a#showTS').click(function() {
 $('#divTS').slideToggle(400);
 return false;
  });
});

</script>

The problem is that this code is only loaded with ajax and does not seem to fire? I would like to run all scripts in the newly loaded view, just as if I hadn't navigated with ajax.

I cannot put this in the site.master as it only loads once and then probably the divs I am trying to hide doesn't exist.

Is there a good way to run scripts in the ajax-loaded div?

© Stack Overflow or respective owner

Related posts about c#

Related posts about asp.net-mvc