|
@@ -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);
|