Advertisement
SUBANGKAR

json-get

Feb 11th, 2019
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var order_now = document.getElementById("order_now");
  2. var delivery_time = document.getElementById("delivery_time").value;
  3. var delivery_addr = document.getElementById("delivery_addr").value;
  4. order_now.addEventListener("click", function () {
  5.     orderReq = new XMLHttpRequest();
  6.     // var url = "submitOrder/";
  7.     var url = "submitOrder?data=" + encodeURIComponent(JSON.stringify({"email": "hey@mail.com", "password": "101010"}));
  8.     orderReq.open("GET", url, true);
  9.     orderReq.setRequestHeader("Content-type", "application/json");
  10.     orderReq.onreadystatechange = function () {
  11.         if (orderReq.readyState === 4 && orderReq.status === 200) {
  12.             var json = JSON.parse(orderReq.responseText);
  13.             console.log(json.email + ", " + json.name)
  14.         }
  15.     };
  16.     // var data = JSON.stringify({"email": "abc", "name": "LaraCroft"});
  17.     orderReq.send("abc");
  18. });
  19.  
  20.  
  21. // Sending a receiving data in JSON format using GET method
  22. //
  23. // var order_now = document.getElementById("order_now");
  24. // order_now.addEventListener("click", function () {
  25. //     var xhr = new XMLHttpRequest();
  26. //     var url = "submitOrder?data=" + encodeURIComponent(JSON.stringify({"email": "hey@mail.com", "password": "101010"}));
  27. //     xhr.open("GET", url, true);
  28. //     xhr.setRequestHeader("Content-Type", "application/json");
  29. //     xhr.onreadystatechange = function () {
  30. //         if (xhr.readyState === 4 && xhr.status === 200) {
  31. //             var json = JSON.parse(xhr.responseText);
  32. //             console.log(json.email + ", " + json.password);
  33. //         }
  34. //     };
  35. //     xhr.send();
  36. // };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement