Datatables ajax post 请求失败,状态码为 500
Datatables ajax post request fails with status code 500
以下 post 请求因 HTTP 错误 500 而失败,但我不明白为什么。
请求如下所示:
var table = table = $('#table-styling').DataTable({
serverSide: true,
pageLength: 25,
processing: true,
language: {
loadingRecords: "Loading...",
processing: "Loading..."
},
ajax: {
url: '/myapplication/myrequest',
type: 'POST',
contentType: "application/json;",
dataType: 'json',
traditional: true,
data: function (d) {
return JSON.stringify(d);
},
headers: {
AntiForgeryToken: $(':input[name="__RequestVerificationToken"]').val()
}
},
// etc.
请求 header 如下所示:
Request URL: https://myapplication.com/myrequest
Request Method: POST
Status Code: 500
Remote Address: 1.1.1.1:443
Referrer Policy: no-referrer-when-downgrade
content-type: text/html; charset=utf-8
date: Fri, 15 May 2020 14:38:22 GMT
server: Kestrel
status: 500
x-powered-by: ASP.NET
:authority: myapplication.com
:method: POST
:path: myapplication/myrequest
:scheme: https
accept: application/json, text/javascript, */*; q=0.01
accept-encoding: gzip, deflate, br
accept-language: en-GB,en-US;q=0.9,en;q=0.8
antiforgerytoken: xxx
content-length: 1600
content-type: application/json;
cookie: xxx
origin: https://myapplication.com
referer: https://myapplication.com/myrequest
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-origin
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36
x-requested-with: XMLHttpRequest
这是一个 ASP.Net MVC 应用程序,我的控制器 returns 视图会像这样触发此 post 请求:
@section Scripts {
<script type="text/javascript">
$(document).ready(function () {
myscript.function.load();
});
</script>
}
正如 HTTP 错误代码所暗示的那样,问题是服务器端问题。
所以我很自然地在我的控制器中放置了一个断点,但在调试时没有命中断点。
我需要做的是使用 IIS Express 启动我的 Web 应用程序,然后才命中断点,我才能够调试真正的服务器端问题。
以下 post 请求因 HTTP 错误 500 而失败,但我不明白为什么。
请求如下所示:
var table = table = $('#table-styling').DataTable({
serverSide: true,
pageLength: 25,
processing: true,
language: {
loadingRecords: "Loading...",
processing: "Loading..."
},
ajax: {
url: '/myapplication/myrequest',
type: 'POST',
contentType: "application/json;",
dataType: 'json',
traditional: true,
data: function (d) {
return JSON.stringify(d);
},
headers: {
AntiForgeryToken: $(':input[name="__RequestVerificationToken"]').val()
}
},
// etc.
请求 header 如下所示:
Request URL: https://myapplication.com/myrequest
Request Method: POST
Status Code: 500
Remote Address: 1.1.1.1:443
Referrer Policy: no-referrer-when-downgrade
content-type: text/html; charset=utf-8
date: Fri, 15 May 2020 14:38:22 GMT
server: Kestrel
status: 500
x-powered-by: ASP.NET
:authority: myapplication.com
:method: POST
:path: myapplication/myrequest
:scheme: https
accept: application/json, text/javascript, */*; q=0.01
accept-encoding: gzip, deflate, br
accept-language: en-GB,en-US;q=0.9,en;q=0.8
antiforgerytoken: xxx
content-length: 1600
content-type: application/json;
cookie: xxx
origin: https://myapplication.com
referer: https://myapplication.com/myrequest
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-origin
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36
x-requested-with: XMLHttpRequest
这是一个 ASP.Net MVC 应用程序,我的控制器 returns 视图会像这样触发此 post 请求:
@section Scripts {
<script type="text/javascript">
$(document).ready(function () {
myscript.function.load();
});
</script>
}
正如 HTTP 错误代码所暗示的那样,问题是服务器端问题。
所以我很自然地在我的控制器中放置了一个断点,但在调试时没有命中断点。
我需要做的是使用 IIS Express 启动我的 Web 应用程序,然后才命中断点,我才能够调试真正的服务器端问题。