第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何訪問(wèn)ajax成功回調(diào)函數(shù)中的$(this)

如何訪問(wèn)ajax成功回調(diào)函數(shù)中的$(this)

元芳怎么了 2019-09-26 09:56:35
看來(lái)我無(wú)法訪問(wèn)jquery ajax成功函數(shù)內(nèi)的$(this)。請(qǐng)參見下面的代碼。 $.ajax({             type: 'post',             url: '<?php echo site_url('user/accept_deny_friendship_request')?>',             data: 'action='+$action+'&user_id='+$user_id,             success: function(response){                //cannot access $(this) here $(this).parent().remove();             }         });
查看完整描述

3 回答

?
慕姐8265434

TA貢獻(xiàn)1813條經(jīng)驗(yàn) 獲得超2個(gè)贊

應(yīng)該$(this)怎么辦 如果在該函數(shù)之外有對(duì)它的引用,則可以將其存儲(chǔ)到變量中。

$('#someLink').click(function() {
    var $t = $(this);
    $.ajax( ... , function() {
        $t.parent().remove();
    });}


查看完整回答
反對(duì) 回復(fù) 2019-09-26
?
犯罪嫌疑人X

TA貢獻(xiàn)2080條經(jīng)驗(yàn) 獲得超4個(gè)贊

查看上下文選項(xiàng)-非常適合我:

$.ajax({
    context: this,
    type: 'post',
    url: '<?php echo site_url('user/accept_deny_friendship_request')?>',
    data: 'action='+$action+'&user_id='+$user_id,
    success: function(response){
       //can access this now!
    }});


查看完整回答
反對(duì) 回復(fù) 2019-09-26
?
千巷貓影

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超7個(gè)贊

如果你想this成為this你的Ajax調(diào)用的情況下,也可以使用.bind()像下面這樣:

$.ajax({
  url: 'some_url'
  success: function(data) {
    // do something 'this'
  }.bind(this)})

它將this成功回調(diào)內(nèi)部的值綁定到this外部。


查看完整回答
反對(duì) 回復(fù) 2019-09-26
  • 3 回答
  • 0 關(guān)注
  • 713 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)