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

    评论

报告相同问题?

悬赏问题

  • ¥15 我这模型写的不对吗?为什么lingo解出来的下面影子价格这一溜少一个变量
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波