如何运行的jQuery的Ajax响应页面? [英] how to run jquery in ajax response page?

查看:131
本文介绍了如何运行的jQuery的Ajax响应页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AJAX分页,这是工作的罚款。

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

现在NewsFeedListID div包含正确的数据。

Now NewsFeedListID div contains the correct data.

现在我必须使用jQuery的响应AJAX页面上,但jQuery是行不通的。

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

谁能帮助?

推荐答案

读你的解释,你的问题的评论部分,我相信乔希在该<一击中href="http://stackoverflow.com/questions/4900460/how-to-run-jquery-in-ajax-response-page/4901322#4901322">answer.

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

您的jQuery的事件不工作的原因是,你附加使用事件处理程序 $('#删除)点击(函数(){警报(成功);} )在锚/按钮,ID为删除​​(这是#DELETE一部分),再后来是主播#DELETE获得的从DOM当您更换#NewsFeedListID的innerHTML删除,所以你要么必须重新连接的事件处理程序#DELETE,或乔希曾建议使用一种称为技术事件委派保持click事件触发,即使要更换的innerHTML。

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.

我会离开它给你看看事件代理,并使用jQuery简化Ajax请求(调查方法的负荷一个非常简单的替代你所描述的),但使用 $('#删除)。住(点击,函数(){警报( 成功);})来解决你眼前的问题

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.

这篇关于如何运行的jQuery的Ajax响应页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆