开发者

Ajax after Ajax

I wrote a we开发者_高级运维bsite which looks like a weblog. My paging is with JQuery Ajax and I have a LIKE button for every post which also is JQuery Ajax. When I change the paging, the new LIKE links don't work with Ajax and open in new tab. Does anyone have any clue how to solve that?


Sounds like you are adding event handlers to all the links at page load, and not adding them again when you replace the links with different ones.

Use the live functionality in jQuery so you don't need to worry about this.


I'm guessing that you're binding events to the "like" buttons with .click() or .bind(). You either need to bind your handlers on the new content when you load it through AJAX or use .live() to bind your "like" handlers.


It worth to mention that .Live() .bind() .delegate() or other similar shorthand methods are old methods. Technically there is nothing wrong with them, but from now on it's better to use .on() event handler. And to get the .live() method effect, bind .on() method to the parent level and define your Selector as the second parameter.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜