简体   繁体   中英

AJAX POST JSON Array Javascript NOT JQUERY

在此处输入图片说明

In this screenshot, a JSON array is being passed to PHP via AJAX without a POST body. I am using this code to implement it:

with(x=new XMLHttpRequest()) open("POST", "http://myweb/api/mobile/v1/jobeventadd?key=cfff"), setRequestHeader("Content-Type", "application/x-www-form-urlencoded"), send("%7B%0A%22SessionID%22%3A%22hn0oqa0u687avsrnev6f5t2nh7%22%2C%0A%22ObjectID%22%3A%226460%22%2C%0A%22ItemName%22%3A%22UologiciPhone%20test%20event%22%2C%0A%22ActivityFrom%22%3A%2201-01-2013%2012%3A00%3A00%22%0A%7D");

But it's not working. How can I do it via XMLHttpRequest? No JQUERY PLEASE

Use the onreadystatechange property to get the response after the success state, and then store the data in a custom header to troubleshoot issues with the POST body:

with(new XMLHttpRequest)
  {
  open("POST",{},true);
  setRequestHeader("Foo", "Bar");
  send("");
  onreadystatechange = handler;
  }

function handler(event)
 {
 !!event.target && !!event.target.readyState && event.target.readyState === 4 && ( console.log(event) );
 }

References

It was same as GET

with(new XMLHttpRequest)
  {
  open("POST","http://google.com",true);
  send("hello=world&no=yes");
  onreadystatechange = function(){};
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM