1

だから私は以下のようにajaxリクエストを送信しています

$('a.new_thumb_update').click(function(e)
{
    e.preventDefault();
    share_id = $(this).attr('share_id');

    $.post('http://studeez.net/resource_layout_files/includes/thumbs_up.php',
    {share_id:share_id},
    function(data)
    {
        alert(data);
        $(this).parent().parent().find('div.thumbs_up').hide();
    });
});

コードは、アラート フィードバックを受け取るコールバック関数まで機能します。

$(this).parent().parent().find('div.thumbs_up').hide();

$(this) を実際の要素に置き換えると、機能します。以下に示すように

$('a.new_thumb_update').parent().parent().find('div.thumbs_up').hide();
4

3 に答える 3

5

ここにキャッシュする必要があり$(this)ます:

$('a.new_thumb_update').click(function (e) {
    e.preventDefault();
    var $self = $(this);
    share_id = $self.attr('share_id');

    $.post('http://studeez.net/resource_layout_files/includes/thumbs_up.php', {
        share_id: share_id
    }, function (data) {
        alert(data);
        $self.parent().parent().find('div.thumbs_up').hide();
    });
});

$(this)jQuery ajax$.postメソッドではアクセスできません。

于 2013-10-28T12:22:24.340 に答える
0

これを試して、

$('a.new_thumb_update').click(function(e){
    e.preventDefault();
    share_id = $(this).attr('share_id');
    var self=this;// assign this to self and use it
    $.post('http://studeez.net/resource_layout_files/includes/thumbs_up.php',
      {share_id:share_id},
      function(data){
        alert(data);
        $(self).parent().parent().find('div.thumbs_up').hide();// use self instead of this
    });
});
于 2013-10-28T12:21:53.390 に答える
0
$('a.new_thumb_update').click(function(e)
{
    e.preventDefault();
    var _this=$(this);// set this in here
    share_id = _this.attr('share_id');

    $.post('http://studeez.net/resource_layout_files/includes/thumbs_up.php',
    {share_id:share_id},
    function(data)
    {
        alert(data);
        _this.parent().parent().find('div.thumbs_up').hide();
    });
});
于 2013-10-28T12:22:14.217 に答える