tmp.js 456 B

123456789101112131415
  1. function sendSyncRequest(url, method, data) {
  2. const xhr = new XMLHttpRequest();
  3. xhr.open(method, url, false);
  4. if (method === 'POST' || method === 'PUT') {
  5. xhr.setRequestHeader('Content-Type', 'application/json');
  6. xhr.send(JSON.stringify(data));
  7. } else {
  8. xhr.send();
  9. }
  10. return JSON.parse(xhr.responseText);
  11. }
  12. let a = sendSyncRequest("https://httpbin.tianyunperfect.cn/post","POST", {"a": 1})
  13. console.log(a);