简体   繁体   English

AJAX POST JSON数组Javascript非JQUERY

[英]AJAX POST JSON Array Javascript NOT JQUERY

在此处输入图片说明

In this screenshot, a JSON array is being passed to PHP via AJAX without a POST body. 在此屏幕截图中,JSON数组通过AJAX传递给PHP,而没有POST正文。 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? 如何通过XMLHttpRequest做到这一点? No JQUERY PLEASE 请勿JQUERY

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: 使用onreadystatechange属性获取成功状态之后的响应,然后将数据存储在自定义标头中以解决POST正文的问题:

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 和GET一样

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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