开发者

Refire the jQuery ready event?

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 pa开发者_如何学Pythonge was already loaded and I am just adding more data from the Ajax response to the DOM.

How can I refire the ready event?


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();
  }
});


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


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.


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 !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜