开发者

jQuery: Hide Ajax Loaded Div After Additional Ajax Request

jQuery('.delete-tag').live('click', function(e) {
    e.preventDefault();

    var id = jQuery(this).attr('id');

    var data_string = "ajax=1&tag-id=" + id + "";

    jQuery.ajax({
        type: "POST",
        url: file_path + "tags/edit/delete/",
        data: dat开发者_C百科a_string,
        dataType: "json",
        success: function(ajax_output) {
            jQuery(this).hide();
        }
    });
});

The .delete-tag link is loaded via ajax in a modal window. I use live() to bind the click event for this link. Ajax runs ok, but I can't get the hide() to work on the ajax loaded link.

Suggestions? Everything works except the hiding.


Once inside the ajax success function, the this points to a different object. Store the origional reference in another variable:

var orig = jQuery(this);
jQuery.ajax({
        type: "POST",
        url: file_path + "tags/edit/delete/",
        data: data_string,
        dataType: "json",
        success: function(ajax_output) {
            orig.hide();
        }
    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜