这是任何限制,在阿贾克斯POST数据的大小?这是、大小、数据、POST

2023-09-10 14:14:07 作者:何以故人初

我想从使用jQuery的Ajax我的网页的MVC操作发送数据的阵列。这是我的jQuery code:

  $('#btnSave)。点击(函数(){
                结果= [];
                $('#tblMatters TBODY tr.mattersRow')。每个(函数(){
                    如果(!($(本).hasClass(警告))){
                        变种项= {};
                        如果($(本).find('td.qbmatter> div.dropdown。)长度大于0){
                            item.QBDescription = $(本).find('td.qbmatter> div.dropdown>一种')。文本();
                        }
                        其他 {
                            item.QBDescription = $(本).find('td.qbmatter)文本()。
                        }
                        变种的id = $(本).find(TD:第一>一种)。文本();
                        。item.Narrative = $(#崩溃+ ID).find(div.scrollCell)文本();
                        item.WorkDate = $(本).find('td.workDate)文本()。
                        。item.Hours = $(本).find('td.hours)文本();
                        item.Person = $(本).find('td.person)文本()。
                        如果($(本).find('td.rate> div.dropdown。)长度大于0){
                            item.Rate = $(本).find('td.rate> div.dropdown>一种')。文本();
                        }
                        其他 {
                            item.Rate = $(本).find('td.rate)文本()。
                        }
                        item.Amount = $(本).find('td.amount)文本()。
                        result.push(项目);
                    }
                });
                。VAR originalRecords = $(#tblSummary tr.summaryTotalRow td.summaryOriginalRecords)文本();
                VAR originalHours = $(#tblSummary tr.summaryTotalRow td.summaryOriginalHours)文本()。
                VAR excludedHours = $(#tblSummary tr.summaryTotalRow td.summaryExcludedHours)文本()。
                VAR totalHours = $(#tblSummary tr.summaryTotalRow td.summaryTotalHours)文本()。
                $阿贾克斯({
                    网址:/首页/ SaveQBMatter
                    键入:POST,
                    数据:JSON.stringify({'事项':结果,originalRecords:originalRecords,originalHours:originalHours,excludedHours:excludedHours,totalHours:totalHours}),
                    数据类型:JSON,
                    传统:真正的,
                    的contentType:应用/ JSON的;字符集= UTF-8,
                    成功:功能(数据){
                        如果(data.status ==成功){
                            警报(成功!);
                            VAR URL ='@ Url.Action(指数,家);
                            window.location.href =网址;
                        } 其他 {
                            警报(错误在数据库级!);
                        }
                    },
                    错误:函数(){
                        警报(发生错误!);
                    }
                });
            });
 

让我expalain一点点。我有一个是动态的建造HTML表,我需要将这些数据存储到数据库中。在jQuery的我不得不通过表中的一个循环,我保存在结果阵列每一行的数据。然后,我通过使用Ajax的MVC操作这些数据。这里是我的问题开始......我已经意识到,有时它会理所应当的,但有时我从Google AJAX错误警报(发生错误!) ; 现在,我明白,当我的结果阵列越来越大出现此错误。例如:如果它包含100-150项目>什么都好,但是当超过〜150>错误

难道是阿贾克斯任何职位限制?我如何可以将其设置为任何尺寸???我真的需要这个功能!任何帮助,请!

我的ActionResult code:

 公众的ActionResult SaveQBMatter(QBMatter []事项,串originalRecords,串originalHours,串excludedHours,串totalHours)
        {
            DBACCESS DBA =新DBACCESS();
            INT QBMatterID = 0;
            INT exportedFileID = 0;
            的foreach(QBMatter QB的事宜)
            {
                dba.InsertQBMatter(qb.QBDescription,qb.Narrative,qb.WorkDate,qb.Person,qb.Hours,qb.Rate,qb.Amount,裁判QBMatterID);
            }
            ExcelTranslator翻译=新ExcelTranslator();
            translator.CreateExcelFile(有关的事项,originalRecords,originalHours,excludedHours,totalHours);
            返回JSON(新{状态=成功,消息=合格});
        }
 

更新:发现我的解决

JSON有最大lenght!我需要增加该值。在web.config中添加以下内容:

 <的appSettings>
  <添加键=ASPNET:MaxJsonDeserializerMembers值=150000/>
< /的appSettings>
 
荷甲,看阿贾克斯能否穿

解决方案

JSON有最大lenght!我需要增加该值。在web.config中添加以下内容:

 <的appSettings>
  <添加键=ASPNET:MaxJsonDeserializerMembers值=150000/>
< /的appSettings>
 

I'm trying to send Array of data from my page to the MVC Action using jQuery Ajax. Here is my jquery code:

$('#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!!!");
                    }
                });
            });

Let me expalain a little bit. I have HTML Table that was builded dynamically and I need to store this data into a Database. In jQuery I have a loop through the table and I store data of every row in result array. Then I pass this data using Ajax into MVC Action. And here is my problem starts... I've realized that sometime it goes as it should be, but sometimes I'm getting an error from ajax alert("An error has occured!!!"); Now I've understood that this error occurs when my result array is getting big. For example: If it contains 100-150 items > Everything is good, but when more than ~150 > Error.

Is it any POST Limit in Ajax? How can I set it up for any sizes??? I really need this functionality! Any help please!

My ActionResult 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" });
        }

UPDATE: Found my Solve!

Json HAS max lenght! I need to increase this value. In web.config add the following:

<appSettings>
  <add key="aspnet:MaxJsonDeserializerMembers" value="150000" />
</appSettings>

解决方案

Json HAS max lenght! I need to increase this value. In web.config add the following:

<appSettings>
  <add key="aspnet:MaxJsonDeserializerMembers" value="150000" />
</appSettings>