在这里,我试图将 AJAX 调用作为单个函数进行,为此我将成功函数名称作为函数参数传递给 AJAX 调用函数。
我尝试编写以下函数:
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("");
}
});
}
函数调用:
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 函数是:
function ReturnFunction(ReturnValue) {
alert(data.data.Table1[0].BillId);
}
当我尝试时,alert(ReturnValue)它显示为object object. 我也试过ReturnValue.data.data.Table1[0].BillId仍然无法使用这些值。AJAX 调用成功,我从中获得了价值,但我无法将结果 JSON 对象传递给其他函数。
如何将 JSON 对象传递给其他函数?请帮我。
largeQ
相关分类