doutan5798 2011-02-04 16:35 采纳率: 100%
浏览 79
已采纳

如何在ajax响应页面中运行jquery?

I am using an AJAX pagination and that is working fine.

It returns the data succesfully. e.g:-

if (xmlHttp.readyState==4)
{ 
document.getElementById("NewsFeedListID").innerHTML=xmlHttp.responseText;
}

Now NewsFeedListID div contains the correct data.

Now I have to use jQuery on that response AJAX page, but jQuery is not working.

Can anyone help?

  • 写回答

3条回答 默认 最新

  • douzou7012 2011-02-04 19:58
    关注

    Reading your explanation in the comments section of your question I believe Josh has hit upon the answer.

    The reason your jQuery event is not working is because, you "attach" the event handlers using $('#delete').click(function() {alert('success');}) to the anchor/button with id "delete" (that's the #delete part), then later that anchor "#delete" get's removed from the DOM when you replace the innerHTML of "#NewsFeedListID", so you would either have to re-attach the event handlers to #delete, or as Josh has suggested use a technique known as event delegation to keep the click event triggering even though you are replacing the innerHTML.

    I'll leave it to you to look into "event delegation" and using jQuery to simplify your ajax requests (look into the method "load" for a very simple alternative to what you are describing) but use $('#delete').live('click',function() {alert('success');}) to solve your immediate problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!