1

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Oded
  • 664
  • 2
  • 9
  • 30

4 Answers4

1

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

Ian Wood
  • 6,515
  • 5
  • 34
  • 73
1

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
  • 4,687
  • 1
  • 24
  • 25
0

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
  • 2,375
  • 1
  • 23
  • 42
0

I think the person asking is because most developer doing jQuery plugins i.e wordpress plugins use the "ready" function.

Everyone here is saying go modify the plugins !

I'm facing the same problem as I'm developing AJAX template for wp and most plugins don't work !

Alaa Murad
  • 166
  • 1
  • 3