且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法使用jquery ajax成功回调函数遍历dom

更新时间:2023-01-17 15:30:15

使用ajax的上下文选项:

Use context option of ajax:

$(".descWrapper h1 a ").on("click", function (e) {
    e.preventDefault();
    $.ajax({
        context:this,
        url: 'ajaxify/gallery.php',
        type: "get",
        data: "id=" + $(this).attr('href'),
        beforeSend: function () {

        },
        success: function (data) {
            //now 'this' here refers to the clicked link
            $(this).parents(".album").next(".gallery").html(data);
        },
        error: function (xhr, status, errorThrown) {
            alert();
        }
    });
});