javascript – Ajax中的POST数据大小是否有限制?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – Ajax中的POST数据大小是否有限制?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3223字,纯文字阅读大概需要5分钟。
内容图文
![javascript – Ajax中的POST数据大小是否有限制?](/upload/InfoBanner/zyjiaocheng/712/eff597d843234e06abdd8e51b3394fb4.jpg)
我正在尝试使用jQuery Ajax从我的页面向MVC Action发送一组数据.这是我的jQuery代码:
$('#btnSave').click(
function () {
result = [];
$('#tblMatters tbody tr.mattersRow').each(function () {
if (!($(this).hasClass('warning'))) {
var item = {};
if ($(this).find('td.qbmatter > div.dropdown').length > 0) {
item.QBDescription = $(this).find('td.qbmatter > div.dropdown > a').text();
} else {
item.QBDescription = $(this).find('td.qbmatter').text();
}
var id = $(this).find("td:first > a").text();
item.Narrative = $("#collapse" + id).find("div.scrollCell").text();
item.WorkDate = $(this).find('td.workDate').text();
item.Hours = $(this).find('td.hours').text();
item.Person = $(this).find('td.person').text();
if ($(this).find('td.rate > div.dropdown').length > 0) {
item.Rate = $(this).find('td.rate > div.dropdown > a').text();
} else {
item.Rate = $(this).find('td.rate').text();
}
item.Amount = $(this).find('td.amount').text();
result.push(item);
}
});
var originalRecords = $("#tblSummary tr.summaryTotalRow td.summaryOriginalRecords").text();
var originalHours = $("#tblSummary tr.summaryTotalRow td.summaryOriginalHours").text();
var excludedHours = $("#tblSummary tr.summaryTotalRow td.summaryExcludedHours").text();
var totalHours = $("#tblSummary tr.summaryTotalRow td.summaryTotalHours").text();
$.ajax({
url: "/Home/SaveQBMatter",
type: "POST",
data: JSON.stringify({ 'Matters': result, 'originalRecords': originalRecords, 'originalHours': originalHours, 'excludedHours': excludedHours, 'totalHours': totalHours }),
dataType: "json",
traditional: true,
contentType: "application/json; charset=utf-8",
success: function (data) {
if (data.status == "Success") {
alert("Success!");
var url = '@Url.Action("Index", "Home")';
window.location.href = url;
} else {
alert("Error On the DB Level!");
}
},
error: function () {
alert("An error has occured!!!");
}
});
});
让我解释一下.我有一个动态构建的HTML表,我需要将这些数据存储到数据库中.在jQuery中,我有一个遍历表的循环,我存储结果数组中每一行的数据.然后我使用Ajax将这些数据传递给MVC Action.
这就是我的问题开始的地方……我已经意识到有时它应该如此,但有时我从Ajax警报中得到一个错误(“发生错误!!!”);现在我已经明白,当我的结果数组变大时会发生这个错误.例如:如果它包含100-150个项目>一切都很好,但是当有超过150的时候错误.
Ajax中是否有POST限制?如何设置任何尺寸?我真的需要这个功能!请帮忙!
我的ActionResult代码:
public ActionResult SaveQBMatter(QBMatter[] Matters, string originalRecords, string originalHours, string excludedHours, string totalHours) {
DBAccess dba = new DBAccess();
int QBMatterID = 0;
int exportedFileID = 0;
foreach (QBMatter qb in Matters) {
dba.InsertQBMatter(qb.QBDescription, qb.Narrative, qb.WorkDate, qb.Person, qb.Hours, qb.Rate, qb.Amount, ref QBMatterID);
}
ExcelTranslator translator = new ExcelTranslator();
translator.CreateExcelFile("", Matters, originalRecords, originalHours, excludedHours, totalHours);
return Json(new { status = "Success", message = "Passed" });
}
更新:找到解决方案
JSON有一个最大长度!我需要增加这个值.在web.config中添加以下内容:
<appSettings>
<add key="aspnet:MaxJsonDeserializerMembers" value="150000" />
</appSettings>
解决方法:
JSON有一个最大长度!我需要增加这个值.在web.config中添加以下内容:
<appSettings>
<add key="aspnet:MaxJsonDeserializerMembers" value="150000" />
</appSettings>
内容总结
以上是互联网集市为您收集整理的javascript – Ajax中的POST数据大小是否有限制?全部内容,希望文章能够帮你解决javascript – Ajax中的POST数据大小是否有限制?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。