I know this is a fairly old question, but there is now a nicer API available natively in newer browsers. The fetch()
method allow you to make web requests.
For example, to request some json from /get-data
:
var opts = {
method: 'GET',
headers: {}
};
fetch('/get-data', opts).then(function (response) {
return response.json();
})
.then(function (body) {
//doSomething with body;
});
See here for more details.