Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 读取AJAX返回的数据_Jquery_Html_Ajax - Fatal编程技术网

Jquery 读取AJAX返回的数据

Jquery 读取AJAX返回的数据,jquery,html,ajax,Jquery,Html,Ajax,我正在做一个ajax请求,它将填充到我的html页面上。我在ajax响应页面上有一个锚标记。我想通过它的id访问html锚标记并显示一个alery 我的代码是: <div id="response"> </div> $.post("destination.php",function(data){ $("#response").html(data); }); 但是我不能在我的页面上这样做,因为这是一个ajax请求,并且在ajax请求之后不会刷新ID。因此,浏览器无法识别

我正在做一个ajax请求,它将填充到我的html页面上。我在ajax响应页面上有一个锚标记。我想通过它的id访问html锚标记并显示一个alery

我的代码是:

<div id="response">
</div>

$.post("destination.php",function(data){
$("#response").html(data);
});
但是我不能在我的页面上这样做,因为这是一个ajax请求,并且在ajax请求之后不会刷新ID。因此,浏览器无法识别id,而此代码无法识别id,这是没有用的


请帮帮我。

这应该适合您:

$('#response').on('click', "#link_test", function(){
    alert("You Clicked Me");
});
活动代表团:

$("#reponse").on("click", "#link_test", function(){

您可以使用事件委派,这意味着您必须将事件侦听器附加到这些按钮的第一个公共祖先

当许多元素必须触发同一个例程时,这是一个很好的选择,如果将来可以通过AJAX将其中一些元素添加到DOM中,则更是如此(这样可以避免页面附加太多事件处理程序)

委托语法

// Event delegation
$( "#firstCommonAncestorThatStillInThePage").on("click", 'a', function() {
    if($(this).is('#link_test')){
        alert( $( this ).text() );
    }
});
$("#reponse").on("click", "#link_test", function(){
// Event delegation
$( "#firstCommonAncestorThatStillInThePage").on("click", 'a', function() {
    if($(this).is('#link_test')){
        alert( $( this ).text() );
    }
});