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

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

無(wú)法在jQuery函數(shù)中返回$ .posted的php文件數(shù)據(jù)

無(wú)法在jQuery函數(shù)中返回$ .posted的php文件數(shù)據(jù)

PHP
繁華開滿天機(jī) 2021-03-30 13:14:54
這是我的自定義jQuery函數(shù):(function($){    $.fn.NotYet = function(arti_id) {        this.append(function() {            var result = 0;            $.post("comment_load.php", {arti_id:arti_id, status:1}, function(data){                console.log(data);          // Returns data from POSTed PHP file                console.log(result);        // Returns 0                //$(this).append(result);   // Not Working                result = data;                console.log(result);        // Returns data from POSTed PHP file            });            console.log(result);            // Returns 0            return result;                  // Returns 0        });                 return this;                        // Returns 0    };})(jQuery);我正在這樣調(diào)用函數(shù):$("div#Comments").NotYet(15);我正在嘗試制作jQuery函數(shù),但無(wú)法將發(fā)布的php文件數(shù)據(jù)返回到<div>容器中。有什么建議么?
查看完整描述

1 回答

?
守著一只汪

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

$.post 是異步方法,它無(wú)法返回任何內(nèi)容。而且您的問(wèn)題是在ajax調(diào)用結(jié)束之前設(shè)置了結(jié)果值。這就是為什么console.log值設(shè)置為的原因0。

  1. 因此,您需要在成功函數(shù)的回調(diào)中進(jìn)行設(shè)置。

  2. 并且在回調(diào)this元素內(nèi)部為無(wú)效元素,因此您需要在傳遞給成功函數(shù)之前聲明另一個(gè)變量,例如var that = this

代碼

(function($) {

      $.fn.NotYet = function(arti_id) {

        this.append(function() {

         var that = this;

          var result = 0;

          $.post("comment_load.php", {

            arti_id: arti_id,

            status: 1

          }, function(data) {

            console.log(data); // Returns data from POSTed PHP file


            $(that).append(data);   //its work

            result = data;


          });

          console.log(result); // Returns 0 //its excute before ajax call

          return result; // its not possible

        });

      };

    })(jQuery);


查看完整回答
反對(duì) 回復(fù) 2021-04-23
  • 1 回答
  • 0 關(guān)注
  • 137 瀏覽

添加回答

舉報(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)