Ajax 和 Mobilefirst

Ajax and Mobilefirst

我现在尝试 Ajax 使用 mobilefirst 来调用业务规则 我在按钮单击处理程序中的 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(响应)中发现了这个错误:

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

当我在 chrome 浏览器上检查元素时,我发现了这个错误:

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 调用