Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. var produkty = ["4105882","4082398","4178248","4178256"]
  2. $.each(produkty, function(k,v){
  3. console.log (k+v);
  4. }
  5. )
  6. function createCORSRequest(method, url) {
  7. var xhr = new XMLHttpRequest();
  8. if ("withCredentials" in xhr) {
  9. // XHR for Chrome/Firefox/Opera/Safari.
  10. xhr.open(method, url, true);
  11. } else if (typeof XDomainRequest != "undefined") {
  12. // XDomainRequest for IE.
  13. xhr = new XDomainRequest();
  14. xhr.open(method, url);
  15. } else {
  16. // CORS not supported.
  17. xhr = null;
  18. }
  19. return xhr;
  20. }
  21.  
  22. // Make the actual CORS request.
  23. function makeCorsRequest() {
  24. // This is a sample server that supports CORS.
  25. var url = 'https://nbsklep.pl/product/get_availability.html?variant_id=4105882&city=Bia%C5%82ystok';
  26.  
  27. var data = new FormData();
  28. data.append("variant_id", produkty);
  29.  
  30. var xhr = createCORSRequest('POST', url);
  31. if (!xhr) {
  32. alert('CORS not supported');
  33. return;
  34. }
  35.  
  36. // Response handlers.
  37. xhr.onload = function() {
  38. var text = xhr.responseText;
  39. var json = JSON.parse(text);
  40. console.log(json)
  41. };
  42.  
  43. xhr.onerror = function() {
  44. console.log('Woops, there was an error making the request.');
  45. };
  46.  
  47. xhr.send(data);
  48. }
  49.  
  50. makeCorsRequest()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement