ajax 参数大小限制,Ajax中的POST数据大小是否有限制?

我正在尝试使用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中,我遍历表有一个循环,我将result数组中每一行的数据存储起来。然后,我使用Ajax将这些数据传递到MVC

Action中。

这是我的问题开始的地方…我已经意识到有时会按预期进行,但是有时我会从Ajax中收到错误消息。alert("An error has

occured!!!");现在我已经了解到,当result数组变大时会发生此错误。例如:如果包含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中添加以下内容:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值