SHARE
TWEET

Untitled

a guest Dec 7th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function createCORSRequest(method, url) {
  2.   var xhr = new XMLHttpRequest();
  3.   if ("withCredentials" in xhr) {
  4.     // XHR for Chrome/Firefox/Opera/Safari.
  5.     xhr.open(method, url, true);
  6.   } else if (typeof XDomainRequest != "undefined") {
  7.     // XDomainRequest for IE.
  8.     xhr = new XDomainRequest();
  9.     xhr.open(method, url);
  10.   } else {
  11.     // CORS not supported.
  12.     xhr = null;
  13.   }
  14.   return xhr;
  15. }
  16.  
  17.  
  18.                 // Make the actual CORS request.
  19.                 function makeCorsRequest() {
  20.                 // This is a sample server that supports CORS.
  21.                 var url = 'https://www.michaelkors.eu/en_PL/server/storeView';
  22.  
  23.                     var data = new FormData();
  24.                     data.append({"country":"Poland","skuId":"359927552","latitude":52.235382,"longitude":21.010353,"excludeStoreType":true,"radius":"25"});
  25.  
  26.                   var xhr = createCORSRequest('POST', url);
  27.                   if (!xhr) {
  28.                     alert('CORS not supported');
  29.                     return;
  30.                   }
  31.                  
  32.                   // Response handlers.
  33.                   xhr.onload = function() {
  34.                     var text = xhr.responseText;
  35.                     var json = JSON.parse(text);
  36.                     console.log(json)
  37.                   };
  38.                  
  39.                   xhr.onerror = function() {
  40.                     console.log('Woops, there was an error making the request.');
  41.                   };
  42.                  
  43.                   xhr.send(data);
  44.                 }
  45.                  
  46.                 makeCorsRequest()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top