【问题标题】:Unable to send large data in Jquery ajax call无法在 Jquery ajax 调用中发送大数据
【发布时间】:2017-02-16 02:54:20
【问题描述】:

您好,我正在开发 MVC4 应用程序。我正在将值保存到数据库。我遇到了错误。

The request filtering module is configured to deny a request where the query string is too long.

我正在进行 ajax 调用并将数据作为 Json 发送如下。

                $.ajax({
                        type: "POST",
                        cache: false,
                        url: '/UploadDocument/SubmitDoc?JsonValue=' + JSON.stringify(SaveUpload) + '&gridData=' + strOrderArr,
    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    headers: {
                        'VerificationToken': forgeryId
                    },
                    success: function (response) {}
});

Web.config

 <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="1073741824" />
      </requestFiltering>
    </security>

我可以知道在将大量数据发布到数据库时,我是否遵循了处理上述情况的好方法?提前致谢。

【问题讨论】:

  • 嗨 Niranjan,构建您的 Web 服务以通过请求正文而不是 URL 接受数据
  • 感谢您的留言。我可以知道什么样的网络服务?上述场景如何实现?可以给我一些网站的链接吗?
  • 我已经放了 maxAllowedContentLength?这与 web.config 中的 maxQueryStringLength 有什么不同吗?
  • 谢谢你,Div。我将浏览您提供的链接。

标签: c# jquery json asp.net-mvc-4 iis


【解决方案1】:

这是一个 POST 请求,但您在查询字符串中传递数据!

在Data参数中传递数据:

 $.ajax({
        type: "POST",
        cache: false,
        url: '/UploadDocument/SubmitDoc',
        data:  JSON.stringify({ JsonValue: SaveUpload, gridData:strOrderArr }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        headers: {
        'VerificationToken': forgeryId
        },
        success: function (response) {}
});

【讨论】:

  • 这真的对我有用。我只是按照上面的方法尝试过。我通过发送大量数据成功执行,它对我来说很好。非常感谢杰里·戈亚尔。
  • 我将数据更改为数据:JSON.stringify({JsonValue: JSON.stringify(SaveUpload), gridData:strOrderArr}),
猜你喜欢
  • 1970-01-01
  • 2021-12-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-29
  • 2020-09-19
  • 1970-01-01
相关资源
最近更新 更多