Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
149
0
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.  var produkty = ["006184"]
  18.     $.each (produkty, function (k,v){
  19.        
  20.         var nr_sklepow = ["710"]
  21.             $.each (nr_sklepow, function (n,w) {
  22.  
  23.                 // Make the actual CORS request.
  24.                 function makeCorsRequest() {
  25.                   // This is a sample server that supports CORS.
  26.                   var url = 'https://www.jula.pl/catalog/narzedzia-i-maszyny/elektronarzedzia-i-maszyny/wkretarki/wkretarki-akumulatorowe/zestaw-narzedzi-one-006184/GetWareHouseStock/';
  27.                  
  28.                     var vars = {
  29.                     data.append('storecode', w);
  30.                     data.append('productCode', v);
  31.                 }
  32.                 data.append(vars)
  33.                  
  34.                   var xhr = createCORSRequest('POST', url);
  35.                   if (!xhr) {
  36.                     alert('CORS not supported');
  37.                     return;
  38.                  }
  39.                  
  40.                   // Response handlers.
  41.                   xhr.onload = function() {
  42.                     var text = xhr.responseText;
  43.                     /*var json = JSON.parse(text);
  44.                     console.log(json)*/
  45.                   };
  46.                  
  47.                   xhr.onerror = function() {
  48.                     console.log('Woops, there was an error making the request.');
  49.                   };
  50.                  
  51.                   xhr.send(data);
  52.                 }
  53.                  
  54.                 makeCorsRequest()
  55.         })
  56.     })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement