views:

50

answers:

3

I am using the jQuery $(document).ready() event on page. All is fine, except that if I am loading data using Ajax calls, the $(document).ready() event does not fire. I guess that it behave in such way because the page was already loaded and I am just adding more data from the Ajax response to the DOM.

How can i refire the ready event ?

A: 

just break the logic that is in the "$(document).ready( function() {});" block out into a separate function. Then the page will call it once when it is "ready", and you can directly call that function when you want to do a refresh.

mlathe
+1  A: 

.load(), .bind(), or .live() will be your friends here....

ToonMariner
+1  A: 

If you need to execute some additionnal Javascript, you might use a function that you call upon Ajax callback onComplete event :

function initJS(){
    //your code here
}

$.ajax({
  url: 'ajax/test.html',
  success: function(data){
  },
  complete: function(){
        initJS();
  }
});
darma