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

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將成功函數(shù)名稱作為函數(shù)參數(shù)傳遞給 AJAX 調(diào)用?

如何將成功函數(shù)名稱作為函數(shù)參數(shù)傳遞給 AJAX 調(diào)用?

C#
開心每一天1111 2021-10-23 17:11:12
在這里,我試圖將 AJAX 調(diào)用作為單個函數(shù)進(jìn)行,為此我將成功函數(shù)名稱作為函數(shù)參數(shù)傳遞給 AJAX 調(diào)用函數(shù)。我嘗試編寫以下函數(shù):function ApiCallFunction(Datatext, ApiName, FunctionName) {  $.ajax({    url: Apiurl + ApiName,    type: "POST",    data: Datatext,    contentType: "application/json",    dataType: "json",    success: function(data) {      var funname = FunctionName + '("' + data + '")';      eval(funname);    },    error: function(error) {      jsonValue = jQuery.parseJSON(error.responseText);      ErrorWhileSave(jsonValue.Message);    },    failure: function(response) {      ErrorWhileSave("");    }  });}函數(shù)調(diào)用:var datatext = {  BillChild: {},  BillDate: "2018-07-23T08:35:32.319Z",  EntryTime: "2018-07-23T08:35:32.319Z",  ExitTime: "2018-07-23T08:35:32.319Z",  TotalTime: "2018-07-23T08:35:32.319Z",  Total: 0,  OtherCharges: 0,  Discount: 0,  TaxableAmount: 0,  TotalTax: 0,  GrandTotal: 0,  RoundOff: 0,  NetAmount: 0,  ByCash: 0,  ByBank: 0,  CashReceived: 0,  BalanceReceivable: 0,  FirmId: 0,  UserId: 0,  BillId: 35,  CustomerId: 0,  BranchId: 0,  BillType: "string",  BillNo: "string",  PaymentType: "string",  Notes: "string",  TaxType: "string",  BankId: "string",  CreatedBy: "string",  HostIp: "string",  BranchTransfer: "string",  ConsultId: 0,  SearchKey: "string",  Flag: "SELECTONE"};var Datatext = (JSON.stringify(datatext));ApiCallFunction(Datatext, "Bill_master", "ReturnFunction");我嘗試使用的 Success 函數(shù)是:function ReturnFunction(ReturnValue) {  alert(data.data.Table1[0].BillId);}當(dāng)我嘗試時,alert(ReturnValue)它顯示為object object. 我也試過ReturnValue.data.data.Table1[0].BillId仍然無法使用這些值。AJAX 調(diào)用成功,我從中獲得了價值,但我無法將結(jié)果 JSON 對象傳遞給其他函數(shù)。如何將 JSON 對象傳遞給其他函數(shù)?請幫我。
查看完整描述

1 回答

?
largeQ

TA貢獻(xiàn)2039條經(jīng)驗 獲得超8個贊

您可以通過不同的方式實現(xiàn)您的目標(biāo)。


方法一簡單地將函數(shù)對象作為參數(shù)賦值


function ApiCallFunction(Datatext, ApiName, onSucess,onError) {

    $.ajax({

        url: Apiurl + ApiName,

        type: "POST",

        data: Datatext,

        contentType: "application/json",

        dataType: "json",

        success: onSucess,

        error: onError,

        failure: function (response) {

            ErrorWhileSave("");

        }

    });

}

并具有以下功能的實現(xiàn):


function ReturnFunction(response){

 //assuming that response is of JSON type

 alert(response.data.Table1[0].BillId);

}


function myError(response){

 console.log(JSON.parse(response.responseText).Message);

}

調(diào)用:


ApiCallFunction(DataText,"Bill_master",ReturnFunction,myError);

方法2如果你碰巧有一個字符串而不是函數(shù)對象


function ApiCallFunction(Datatext, ApiName, FunctionName) {

    $.ajax({

        url: Apiurl + ApiName,

        type: "POST",

        data: Datatext,

        contentType: "application/json",

        dataType: "json",

        success: function (data) {

             window[FunctionName].apply(this,data);

        },

        error: function (error) {

            jsonValue = jQuery.parseJSON(error.responseText);

            ErrorWhileSave(jsonValue.Message);

        },

        failure: function (response) {

            ErrorWhileSave("");

        }

    });

}

調(diào)用:


ApiCallFunction(DataText,"Bill_master","ReturnFunction");


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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