Ajax不起作用(不知道为什么)

Ajax is not working (don't know why)

本文关键字:为什么 不知道 不起作用 Ajax      更新时间:2023-09-26

大家好,提前感谢大家!

我想用Ajax做一件简单的事情,但不起作用:按下按钮,用同一文件夹中的另一个更改html。是javascript的问题,但我无法确定问题所在。我是个网页设计的新手。

$(".about .ajax").on("click",function(e){
var section = $(this).closest("section");
var href = $(this).attr("href");
$.ajax({
    url:href,
    dataType:"html",
    success:function(data){
        var contenido = $("#about",data);
        section.html(contenido);
    }
});
e.preventDefault();
});

jsfiddle

我认为您没有正确地将其绑定回。

我想你想要这样的东西:

success:function(data){
    $("#about").html(data);
}

传递data作为第二个参数将限制jquery查找正确的元素。