asp.net-mvc - Datatables ajax 发布请求失败,状态码为 500
问题描述
以下发布请求失败并出现 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.
请求标头如下所示:
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 应用程序,我的控制器返回视图,它会触发这个 post 请求,如下所示:
@section Scripts {
<script type="text/javascript">
$(document).ready(function () {
myscript.function.load();
});
</script>
}
解决方案
正如 HTTP 错误代码所建议的那样,问题是服务器端问题。
所以很自然地我在我的控制器中放置了一个断点,但是在调试时断点没有被命中。
我需要做的是使用 IIS Express 启动我的 Web 应用程序,然后断点才被击中,并且我能够调试真正的服务器端问题。
推荐阅读
- html - 使用带有包装器的 CSS Grid 的理想方式?
- python - Django - form_valid() 变量未定义
- javascript - 如果我要设置与给定查询字符串参数相关的日期,如何获得正确的星期几?
- javascript - 使用 Jest 和 Supertest 测试 React 时出现服务器导出问题
- javascript - Summernote:TextArea 不加载 SQL 数据,但文字可以
- javascript - 有没有一种方法可以在不确认 AWS Cognito 用户池中用户的账户状态的情况下验证电子邮件?
- html - 如何修复表格中的 CSS“空白:nowrap”?
- sql-server - 将多行合并为单个表上的一行
- vue.js - 如何使用 VueJS 在 Sweetalert2 中显示多个选择选项?
- amazon-web-services - 亚马逊 API:如何使用亚马逊的 MWS API 通过 ASIN 获取产品信息?