【问题标题】:Angular Onsen UI Ajax callAngular Onsen UI Ajax call
【发布时间】:2022-01-11 03:49:20
【问题描述】:

我开始学习使用 Monaca 编写应用程序,我正在编辑一个使用 Onsen 和 Angular 编写的示例应用程序。

我希望能够在需要时从服务器上的远程文件中获取数据,因为数据会定期更改。

通过 Ajax 或 HTTPRequest 获取数据的正确方法是什么?以下似乎不起作用。

function getDataPullCheck() { 
  alert("getDataPullCheck");
  angular.request({
    url: "https://***my file***",
    method: 'POST',
    success: function (data) { 
      console.log(data); 
      alert{data};
    },
    error: function (x, t, m) {
      alert{'Error'};
    }
  });

}

有人可以更正我的代码或为我指明一个将远程数据导入应用程序的好教程的方向吗?

非常感谢。

【问题讨论】:

    标签: angularjs ajax onsen-ui monaca


    【解决方案1】:

    所以我意识到这可以用简单的 JS 来完成。

    var xhttp = new XMLHttpRequest();
    xhttp.withCredentials = false;
    xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
          var jsonResponse = JSON.parse(this.responseText);
          displayResult(jsonResponse,ptype);
        }
    };
    xhttp.open("GET", <<MYFILE>>, true);
    xhttp.send();
    

    【讨论】:

      猜你喜欢
      • 2014-11-07
      • 2020-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-09
      • 1970-01-01
      • 2018-01-21
      相关资源
      最近更新 更多