gpt4 book ai didi

javascript - 想要将 $http 方法的响应分配给 angularjs 中的 javascript 变量

转载 作者:行者123 更新时间:2023-11-28 03:23:12 26 4
gpt4 key购买 nike

我试图将从后端获得的存储在响应对象中的整个数据分配给一个javascript变量,最后主函数$scope.SelectedTerms应该返回该变量。但我得到的是变量数据我正在存储的响应未定义我正在使用 anjularjs

$scope.SelectedTerms = function (feeHeadId,feeHead){
var data="";
var datatosend="";
var formData = {
customerId : $scope.customerId,
feeHeadId : feeHeadId,
selectedOptions : feeHead.feeHeadSelectedOption.display.split("+"),
payterms : feeHead.pmntTerms
}

$http({

url : '<%= fileReader.getValue("ICOLLECT_SERVICE") %>?<%=ICollectConstants.FLOW_NAME_PARAM%>=<%= ICollectConstants.FLOW_NAME %>&<%=ICollectConstants.MERC_ID%>=<%= icMerchantMasterBean.getIcMerchantMasterId() %>&<%= ICollectConstants.BANK_ID%>=<%= icMerchantMasterBean.getIcBankMasterId()%>&req_id=validateFeeAndSendResponse&checksum=BFEDE97EF99CCF9C1362EBFE7C94E3233ED6E2B7637AC7BDB34AC916D9BAC3AD&reqtoken=<%=req_token%>'+'&method=TEST' ,
method : "POST",
params : {
jsondataforST:btoa(angular.toJson(formData)),
responseType:"1",
backUrl :'<%= backUrl%>',
icMerchantMasterId : <%= icMerchantMasterBean.getIcMerchantMasterId()%>,
icMerchantBankId : <%= icMerchantMasterBean.getIcBankMasterId()%>
}
}).then(function Success(response){
if(response.data.statusCode=="100"){
data = response.data;
//datatosend;
/*function funccarringSubfee(){
var value = data[feeHeadId];
console.log("value inside subFunction");
console.log(value);
return value;

}*/
//$scope.separateTermLogic(feeHead,data);
}
}, function error(response){
console.log("error occured");
});

return data; //it returns undefinied

};

最佳答案

嘿伙计们,这些对我有用...谢谢您的回复...我刚刚注入(inject)了 $d

   $scope.SelectedTerms = function (feeHeadId,feeHead){
console.log(" async SelectedTerm function Started");
var data="";
var datatosend="";
var formData = {
customerId : $scope.customerId,
feeHeadId : feeHeadId,
selectedOptions : feeHead.feeHeadSelectedOption.display.split("+"),
payterms : feeHead.pmntTerms
}
var deferred = $q.defer();//newely added
$http({

url : '<%= fileReader.getValue("ICOLLECT_SERVICE") %>?<%=ICollectConstants.FLOW_NAME_PARAM%>=<%= ICollectConstants.FLOW_NAME %>&<%=ICollectConstants.MERC_ID%>=<%= icMerchantMasterBean.getIcMerchantMasterId() %>&<%= ICollectConstants.BANK_ID%>=<%= icMerchantMasterBean.getIcBankMasterId()%>&req_id=validateFeeAndSendResponse&checksum=BFEDE97EF99CCF9C1362EBFE7C94E3233ED6E2B7637AC7BDB34AC916D9BAC3AD&reqtoken=<%=req_token%>'+'&method=TEST' ,
method : "POST",
params : {
jsondataforST:btoa(angular.toJson(formData)),
responseType:"1",
backUrl :'<%= backUrl%>',
icMerchantMasterId : <%= icMerchantMasterBean.getIcMerchantMasterId()%>,
icMerchantBankId : <%= icMerchantMasterBean.getIcBankMasterId()%>
}
}).then(function Success(response){
if(response.data.statusCode=="100"){
data = response.data;
console.log("async SelectedTerms:"+feeHeadId+":"+feeHead+":"+data);
feesforUniquekey = processSelectedTermsResponse(feeHeadId,feeHead,data);
deferred.resolve(feesforUniquekey);// These Resolve() sends the data .
}
}, function error(response){
console.log("async error occured");
deferred.reject({ message: "Really bad" });
});

//return data;
console.log(" async Selected term function End");
return deferred.promise;
};

关于javascript - 想要将 $http 方法的响应分配给 angularjs 中的 javascript 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58930432/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com