|
@@ -54,11 +54,17 @@ function my_tip(string) {
|
|
|
}, 2000)
|
|
|
}
|
|
|
|
|
|
-// 发送同步请求 let a = sendSyncRequest("https://httpbin.tianyunperfect.cn/ip","GET",1)
|
|
|
-function sendSyncRequest(url, method, data) {
|
|
|
+// 发送同步请求 let a = sendSyncRequest("https://httpbin.tianyunperfect.cn/ip","GET",null,null)
|
|
|
+function sendSyncRequest(url, method, data, headers) {
|
|
|
const xhr = new XMLHttpRequest();
|
|
|
xhr.open(method, url, false);
|
|
|
|
|
|
+ if (headers) {
|
|
|
+ for (const key in headers) {
|
|
|
+ xhr.setRequestHeader(key, headers[key]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if (method.match(/^(POST|PUT)$/i)) {
|
|
|
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
|
xhr.send(JSON.stringify(data));
|