Skip to content

Commit 6945375

Browse files
AiYuZhenAiZhenArgoZhang
authored
修复 Ajax 组件 body 内容错误问题 (#5874)
* refactor: 重构代码 * chore: bump version 9.5.11-beta02 --------- Co-Authored-By: AiZhen <[email protected]> Co-Authored-By: Argo Zhang <[email protected]>
1 parent bb4c827 commit 6945375

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.5.11-beta01</Version>
4+
<Version>9.5.11-beta02</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/wwwroot/modules/ajax.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,24 @@
1919
if (headers['Content-Type'] === void 0) {
2020
headers['Content-Type'] = 'application/json; charset=utf-8'
2121
}
22-
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();
26-
}
27-
result = await fetch(url, {
22+
23+
const fetchOptions = {
2824
method: method,
29-
headers: headers,
30-
body: postData
31-
});
25+
headers: headers
26+
}
27+
28+
if (method === 'PUT' || method === 'POST') {
29+
const contentType = headers['Content-Type'];
30+
let postData = null;
31+
if (data) {
32+
postData = JSON.stringify(data);
33+
if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
34+
postData = new URLSearchParams(data).toString();
35+
}
36+
fetchOptions.body = postData;
37+
}
38+
}
39+
result = await fetch(url, fetchOptions);
3240
if (toJson === true) {
3341
result = await result.json()
3442
}

0 commit comments

Comments
 (0)