Datatables ajax post请求失败,状态码为500。

问题描述 投票:-1回答:1

下面的帖子请求以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>
}

asp.net-mvc http http-error
1个回答
0
投票

问题是,正如HTTP错误代码所提示的那样,是服务器端的问题。

所以我很自然地在我的控制器中放了一个断点,但是在调试的时候并没有打到断点。

我需要做的是用IIS Express启动我的web应用,只有这样断点才被击中,我才能调试出真正的服务器端问题。

© www.soinside.com 2019 - 2024. All rights reserved.