diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index fe980211a17..d9e7de776b5 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@  - 9.5.9 + 9.5.10 diff --git a/src/BootstrapBlazor/wwwroot/modules/ajax.js b/src/BootstrapBlazor/wwwroot/modules/ajax.js index 793d042c6b4..921e9dfbd29 100644 --- a/src/BootstrapBlazor/wwwroot/modules/ajax.js +++ b/src/BootstrapBlazor/wwwroot/modules/ajax.js @@ -4,6 +4,7 @@ url: null, data: null, toJson: true, + headers: { 'Content-Type': 'application/json; charset=utf-8' }, ...option } @@ -14,13 +15,19 @@ let result = null; try { - const { toJson, url, method, data } = option; + const { toJson, url, method, data, headers } = option; + if (headers['Content-Type'] === void 0) { + headers['Content-Type'] = 'application/json; charset=utf-8' + } + const contentType = headers['Content-Type']; + let postData = JSON.stringify(data); + if (contentType.indexOf('application/x-www-form-urlencoded') > -1) { + postData = new URLSearchParams(data).toString(); + } result = await fetch(url, { method: method, - headers: { - 'Content-Type': 'application/json' - }, - body: method === 'POST' ? JSON.stringify(data) : null + headers: headers, + body: postData }); if (toJson === true) { result = await result.json()