如何运行的jQuery的Ajax响应页面?页面、jQuery、Ajax

2023-09-10 20:09:54 作者:呐誰!請伱滚幵

我正在使用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.

谁能帮助?

推荐答案

读你的解释,你的问题的评论部分,我相信乔希在该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.