gpt4 book ai didi

javascript - Ajax 和移动优先

转载 作者:行者123 更新时间:2023-12-03 09:25:47 26 4
gpt4 key购买 nike

我现在尝试使用 mobilefirst 进行 Ajax 来调用业务规则,我在按钮单击处理程序内的 main.js 文件中尝试了此操作:

   $.ajax({
type: "POST",
url: "https://brsv2-0cc90e37.ng.bluemix.net/DecisionService/rest/vacationsRuleApp/164.0/vacationsRuleProject/1.0",
async: false,
withCredentials: true,
headers: {Authorization: "Basic " + "credentials"},
data: {
"employeeID": "anything",
"loanAmount": 2320,
"theEmployee": {
"seniority": 3,
"annualSalary": 10517320,
"nbOfExtraVacationDaysBasedOnSeniority": 10517320
},
"creditAmount": 20000,
"__DecisionID__": "string",
"AnnualSalary": 20000
}
}).done(function(response) {
alert("Success");
alert(JSON.stringify(response)); // if you're into that sorta thing


}).fail(function(response) {
alert("Fail");

alert(JSON.stringify(response)); // if you're into that sorta thing

});

然后我尝试获取错误,我从 json.stringify(response) 中发现了这个:

网络错误:无法在“XMLHttpRequest”上执行“发送”:无法加载“https://brsv2-0cc90e37.ng.bluemix.net/DesicionService/rest/vacationsRuleApp/164.0/vacationsRuleProject/1.0” .

当我在 Chrome 浏览器上检查element 时,我发现此错误:

XMLHttpRequest cannot load https://brsv2-0cc90e37.ng.bluemix.net/DecisionService/rest/vacationsRuleApp/164.0/vacationsRuleProject/1.0. No 'Access-Control-Allow-Origin' header is present on the requested resource

最佳答案

您将前端和后端开发混合在一起。 var url = require('url'), https = require('https');代码适用于 Node.Js 后端。上面引用的模块是 Node.Js 模块。

<script src="js/require.js"></script>是前端代码。

但是您可以使用 require.js也在前端。

如果您想从混合应用程序调用业务规则服务,您将需要使用类似 Jquery 的 ajax call 功能。进行 REST API 调用

关于javascript - Ajax 和移动优先,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31678854/

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