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.
精彩评论