SUBANGKAR

js-orderreq

Feb 11th, 2019
141
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");
  3. var delivery_addr = document.getElementById("delivery_addr");
  4. order_now.addEventListener("click", function () {
  5.     orderReq = new XMLHttpRequest();
  6.     var url = "submitOrder/";
  7.     orderReq.open("POST", url, true);
  8.     orderReq.setRequestHeader("Content-type", "application/json");
  9.     orderReq.onreadystatechange = function () {
  10.         if (orderReq.readyState === 4 && orderReq.status === 200) {
  11.             var json = JSON.parse(orderReq.responseText);
  12.             console.log(json.email + ", " + json.name)
  13.         }
  14.     };
  15.     var data = JSON.stringify({"email": delivery_time.value, "name": "LaraCroft"});
  16.     orderReq.send(data);
  17. });
RAW Paste Data