$http.get('/someUrl').success(function(data, status, headers, config) {// this callback will be called asynchronously// when the response is available}).error(function(data, status, headers, config) {// called asynchronously if an error occurs// or server returns response with an error status.});
function get(path) {var form = document.createElement("form");form.setAttribute("method", "get");form.setAttribute("action", path);document.body.appendChild(form);form.submit();}
get('/my/url/')
//create request with its porpertiesvar request = new httpRequest();request.method = "GET";request.url = "https://example.com/api?parameter=value";
//create callback for success containing the responserequest.success = function(response) {console.log(response);};
//and a fail callback containing the errorrequest.fail = function(error) {console.log(error);};
//and finally send it awayrequest.send();
// Create the XHR object.function createCORSRequest(method, url) {var xhr = new XMLHttpRequest();if ("withCredentials" in xhr) {// XHR for Chrome/Firefox/Opera/Safari.xhr.open(method, url, true);} else if (typeof XDomainRequest != "undefined") {// XDomainRequest for IE.xhr = new XDomainRequest();xhr.open(method, url);} else {// CORS not supported.xhr = null;}return xhr;}
// Make the actual CORS request.function makeCorsRequest() {// This is a sample server that supports CORS.var url = 'http://html5rocks-cors.s3-website-us-east-1.amazonaws.com/index.html';
var xhr = createCORSRequest('GET', url);if (!xhr) {alert('CORS not supported');return;}
// Response handlers.xhr.onload = function() {var text = xhr.responseText;alert('Response from CORS request to ' + url + ': ' + text);};
xhr.onerror = function() {alert('Woops, there was an error making the request.');};
xhr.send();}
// Create a request variable and assign a new XMLHttpRequest object to it.var request = new XMLHttpRequest()
// Open a new connection, using the GET request on the URL endpointrequest.open('GET', 'restUrl', true)
request.onload = function () {// Begin accessing JSON data here}
// Send requestrequest.send()
let url = 'https://www.randomtext.me/api/lorem';
// to only send GET request without waiting for response just callfetch(url);
// to wait for results use 'then'fetch(url).then(r=> r.json().then(j=> console.log('\nREQUEST 2',j)));
// or async/await(async()=>console.log('\nREQUEST 3', await(await fetch(url)).json()))();