簡體   English   中英

json ajax調用以200 OK返回成功,但由於無效字符而出錯

[英]json ajax call returning success with 200 OK but goes to error with Invalid character

我的項目是MVC Web應用程序,我正在使用ajax調用來獲取大量的JSON數據列表。

這是代碼(我不確定我缺少什么):

  $.ajax({
            url: url, //server
            type: "POST",
            async: true,
            data: { id: id },
            dataType: "json",
            success: function (data) {
                debugger;
                jQuery.each(data, function (i, val) {

//Success code


            },
            error: function (xhr, ajaxOptions, thrownError) {
                console.log(xhr.status);
                console.log(thrownError);
                window.baseShowModalOkCancel("<p>Backlog Data</p>", "<p>Error in Database</p>", "ERROR");
            }
        });
    }

動作控制器:(這是return語句中的post方法,我可以看到帶有數據的對象列表。

   [HttpPost]
    [OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
    public ActionResult GetBacklogWithData(string id)
    {
        using (var db = new LiensTrackerEntities())
        {

            List<BackLogDataList> backLogData = new List<BackLogDataList>();
            List<BackLogData> backLog;

               backLog = db.BackLogDatas.OrderBy(x =>x.CaseNumber).ToList();
                foreach (var item in backLog)
                {
                    BackLogDataList backLogDataList = new BackLogDataList
                    {
                        FileNo = item.FileNo,
                        BackLogId = item.BackLogID,
                        FirstName = item.FirstName,
                        LastName = item.LastName,
                        Middle = item.Middle,
                        Suffix = item.Suffix,
                        Address = item.Address,
                        Address2 = item.Address2,
                        City = item.City,
                        St = item.ST,
                        Zip = item.SP1ZIP,                           
                        AmaesRecordCreatedDate = item.AMAESRecordCreatedDate != null ? item.AMAESRecordCreatedDate.ToString().Split(' ')[0] : null,
                        AddedInRecipient = item.AddedInRecipient
                    };
                    backLogData.Add(backLogDataList);
                }

            }



            return Json(backLogData, JsonRequestBehavior.AllowGet);
        }
    }

它返回200 ok,但是當我查看控制台時執行錯誤功能,發現以下錯誤:

在此處輸入圖片說明

您的錯誤是由於json字符串的最大長度引起的。 解決方案是

JavaScriptSerializer期間ASP.NET MVC中的MaxJsonLength異常

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM