Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it any limit for POST data size in Ajax?
    primarykey
    data
    text
    <p>I'm trying to send an array of data from my page to the MVC Action using jQuery Ajax. Here is my jQuery code:</p> <pre><code>$('#btnSave').click( function () { result = []; $('#tblMatters tbody tr.mattersRow').each(function () { if (!($(this).hasClass('warning'))) { var item = {}; if ($(this).find('td.qbmatter &gt; div.dropdown').length &gt; 0) { item.QBDescription = $(this).find('td.qbmatter &gt; div.dropdown &gt; a').text(); } else { item.QBDescription = $(this).find('td.qbmatter').text(); } var id = $(this).find("td:first &gt; 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 &gt; div.dropdown').length &gt; 0) { item.Rate = $(this).find('td.rate &gt; div.dropdown &gt; 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!!!"); } }); }); </code></pre> <p>Let me explain a little bit. I have an HTML table that was built dynamically and I need to store this data into a database. In jQuery I have a loop going through the table and I store data of every row in the <code>result</code> array. Then I pass this data using Ajax into MVC Action.</p> <p>And here is where my problem starts... I've realized that sometimes it goes as it should be, but sometimes I'm getting an error from Ajax <code>alert("An error has occured!!!");</code> Now I've understood that this error occurs when my <code>result</code> array is getting big. For example: If it contains 100-150 items > everything is good, but when there are more than ~150 > Error.</p> <p>Is there any POST limit in Ajax? How can I set it up for any sizes? I really need this functionality! Any help please!</p> <p>My ActionResult Code:</p> <pre><code>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" }); } </code></pre> <p><strong>UPDATE: Found a solution</strong></p> <p>JSON has a maximum length! I need to increase this value. In web.config add the following:</p> <pre><code>&lt;appSettings&gt; &lt;add key="aspnet:MaxJsonDeserializerMembers" value="150000" /&gt; &lt;/appSettings&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload