ajax post参数长度限制,Ajax中的POST数据大小是否有限制?
我想使用jQuery Ajax將我的頁面中的數據數組發送到MVC Action。這里是我的jQuery代碼:Ajax中的POST數據大小是否有限制?
$('#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" });
}
UPDATE:找到一個解決辦法
JSON的最大長度!我需要增加這個值。在web.config中添加以下內容:
2013-11-27
Bryuk
+0
錯誤的原因是別的。使用Firebug /使用Visual Studio的斷點看到你真正的問題是什么 –
+0
您將需要返回代碼從調試警報的/ dev-工具 –
+0
Guuys最低。請。我仍然需要幫助! –
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的ajax post参数长度限制,Ajax中的POST数据大小是否有限制?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: fpdisp4.exe是什么进程 有什么
- 下一篇: php 解析mib文件,Mib库解析