weixin_33713707 2015-07-28 14:11 采纳率: 0%
浏览 38

Ajax和Mobilefirst

I tried now Ajax with mobilefirst to invoke business rules i tried this in my main.js file inside a button click handler:

   $.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

            });

then i tried to get the error and i found this from the json.stringify(response):

NetworkError: Failed to execute 'send' on 'XMLHttpRequest':Failed to load 'https://brsv2-0cc90e37.ng.bluemix.net/DesicionService/rest/vacationsRuleApp/164.0/vacationsRuleProject/1.0.

and when i inspectelement on my chrome browser i find this error:

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

  • 写回答

1条回答 默认 最新

  • weixin_33701564 2015-07-28 15:57
    关注

    You are mixing frontend and backend dev together. The var url = require('url'), https = require('https'); code is meant for the Node.Js backend. The modules referenced above are Node.Js modules.

    <script src="js/require.js"></script> is frontend code.

    You can however use require.js on the frontend as well.

    If you want to call the Business Rules service from your hybrid app you will need to use something like Jquery using the ajax call to make a REST API call

    评论

报告相同问题?