tianyun 2 년 전
부모
커밋
3ef7b51ed5
2개의 변경된 파일16개의 추가작업 그리고 2개의 파일을 삭제
  1. 1 1
      simple-demo/js/util.js
  2. 15 1
      tmp.js

+ 1 - 1
simple-demo/js/util.js

@@ -59,7 +59,7 @@ function sendSyncRequest(url, method, data) {
     const xhr = new XMLHttpRequest();
     xhr.open(method, url, false);
 
-    if (method === 'POST' || method === 'PUT') {
+    if (method.match(/^(POST|PUT)$/i)) {
         xhr.setRequestHeader('Content-Type', 'application/json');
         xhr.send(JSON.stringify(data));
     } else {

+ 15 - 1
tmp.js

@@ -1 +1,15 @@
-123
+function sendSyncRequest(url, method, data) {
+    const xhr = new XMLHttpRequest();
+    xhr.open(method, url, false);
+
+    if (method === 'POST' || method === 'PUT') {
+        xhr.setRequestHeader('Content-Type', 'application/json');
+        xhr.send(JSON.stringify(data));
+    } else {
+        xhr.send();
+    }
+
+    return JSON.parse(xhr.responseText);
+}
+let a = sendSyncRequest("https://httpbin.tianyunperfect.cn/post","POST", {"a": 1})
+console.log(a);