Angular Onsen UI Ajax call

102 Views Asked by At

I am beginning to learn writing apps using Monaca and I have a sample application I am editing which is written in Onsen and Angular.

I would like to be able to get data from a remote file on my server when needed as data will change regularly.

What is the correct way to get the data via Ajax or HTTPRequest? THe following doesn't seem to work.

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'};
    }
  });

}

Could someone correct my code or point me in the direction of a good tutorial for getting remote data into the app?

Many thanks.

1

There are 1 best solutions below

0
RobertyBob On

So I realised this can be done in simple 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();