发送Ajax调用时出错[内部服务器错误500]

问题描述:

我正在循环中发送ajax调用。它仅适用于前两个迭代工作正常,并抛出异常的内部服务器错误500的描述后“的JSON请求是太大,被序列”这里是代码:发送Ajax调用时出错[内部服务器错误500]

<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;  
    } 

服务器端:

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

请问我该如何处理它?

+0

您可能需要在web.config中设置'maxJsonLength'。 http://stackoverflow.com/questions/10966328/the-json-request-was-too-large-to-be-deserialized – PSL

您必须将maxJsonLength属性调整为web.config中较高的值才能解决问题。

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

aspnet:MaxJsonDeserializerMembers更高的价值,

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

如果这些选项不工作,你可以尝试建立在这个线程指定使用JSON.NET自定义JSON值供应商工厂。

+0

谢谢你现在的工作。与

+0

@BaqerNaqvi我很高兴我能够帮助,如果此作品标记为接受,所以其他人可以看到这是正确的答案,并提高投票,如果你可以 – MZaragoza

+0

对不起,我忘了。 :) –