开发者

jQuery: Hide Ajax Loaded Div After Additional Ajax Request

开发者 https://www.devze.com 2023-02-11 19:55 出处:网络
jQuery(\'.delete-tag\').live(\'click\', function(e) { e.preventDefault(); var id = jQuery(this).attr(\'id\');
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

精彩评论

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