数据表ajax发布请求失败,状态码为500

时间:2020-05-15 14:49:52

标签: asp.net-mvc http http-error

以下发布请求失败,出现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应用程序,我的控制器返回该视图,从而触发此发布请求,如下所示:

@section Scripts {
    <script type="text/javascript">
        $(document).ready(function () {
            myscript.function.load();
        });
    </script>
}

1 个答案:

答案 0 :(得分:0)

该问题是HTTP错误代码所建议的服务器端问题。

自然地,我在控制器中放置了一个断点,但是在调试时没有碰到断点。

我需要做的是使用IIS Express启动我的Web应用程序,然后才遇到断点,并且我能够调试真正的服务器端问题。