Skip to content

Commit eab5ccc

Browse files
author
AiZhen
committed
修复 Ajax 组件 "TypeError: Failed to execute 'fetch' on 'Window': equest with GET/HEAD method cannot have body. " 错误问题。
1 parent bb4c827 commit eab5ccc

File tree

1 file changed

+6
-3
lines changed
  • src/BootstrapBlazor/wwwroot/modules

1 file changed

+6
-3
lines changed

src/BootstrapBlazor/wwwroot/modules/ajax.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@
2020
headers['Content-Type'] = 'application/json; charset=utf-8'
2121
}
2222
const contentType = headers['Content-Type'];
23-
let postData = JSON.stringify(data);
24-
if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
25-
postData = new URLSearchParams(data).toString();
23+
let postData = null;
24+
if (data) {
25+
postData = JSON.stringify(data);
26+
if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
27+
postData = new URLSearchParams(data).toString();
28+
}
2629
}
2730
result = await fetch(url, {
2831
method: method,

0 commit comments

Comments
 (0)