2

i am sending ajax call in a loop. it works fine only for first two iterations and after that throws exception internal server error 500 with description "The JSON request was too large to be serialized" here is code :

<script>
    var things = new Array();
    var total = 0;
    function Load() {
        $.ajaxSetup({ cache: true, jsonpCallback: 'quranData' }); // define ajax setup
        for (var counter = 1; counter < 4; counter++) {
            (function (counter) {
                setTimeout(function () {
                    $.getJSON("http://api.globalquran.com/surah/" + counter + "/quran-simple?jsoncallback=?", {
                        format: "jsonp"
                    }, function (Obj) {
                        $.each(Obj.quran, function (i, by)
                        {
                            $.each(by, function (verseNo, line)
                            {
                                var obj = new Object();
                                obj.surah = line.surah;
                                obj.ayah = line.ayah;
                                obj.verse = line.verse;
                                things.push(obj);
                                total++;
                            });
                        });
                    });
                }, counter * 500);
            }(counter));
        }
        return false;    
    }

server side :

[HttpPost]
        public ActionResult DB_Rola(List<thing> things, int count)
        {
            return Json(new { IsSuccess = true });
        }

kindly show me how to deal with it ?

  • You may want to set `maxJsonLength` in the web.config. http://stackoverflow.com/questions/10966328/the-json-request-was-too-large-to-be-deserialized – PSL Dec 22 '13 at 19:09

1 Answers1

0

You have to adjust the maxJsonLength property to a higher value in web.config to resolve the issue.

<system.web.extensions>
    <scripting>
        <webServices>
            <jsonSerialization maxJsonLength="2147483644"/>
        </webServices>
    </scripting>
</system.web.extensions>

or a higher value for aspnet:MaxJsonDeserializerMembers,

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

If those options not working you could try creating a custom json value provider factory using JSON.NET as specified in this thread.

MZaragoza
  • 10,108
  • 9
  • 71
  • 116