ajax错误500&MVC中的内部服务器错误

问题描述:

我使用ajax方法来调用控制器并获取数据,并将其转换为json或list并设置一个jQuery DataTable .用1000条记录可以正常工作,但是当我获取5000条以上的记录时,ajax方法会给我:

I used ajax method to call the controller and fetch the data and convert it to json or list and set a jquery DataTable. With 1000 records it's working fine, but when I fetch more than 5000 records, ajax method gives me:

500内部服务器错误

500 Internal server error

这是我的代码:

 $('#btnAllData').click(function () {

    $.ajax({
        url: 'PartMaster/GridLoad',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (Result) {
            debugger;
            var pageload = Result.split('|');
            var status = (pageload[0])

            if (status == "ERROR") {
                Error(pageload[1]);

            }
            else {
                var Partdetails = (pageload[0]);
                //var LocDetails = JSON.parse(pageload[2]);

            }

            //gridDetails(status1);

        },

        error: function (xhr, ajaxOptions, thrownError) {
            alert(xhr.status);
            alert(thrownError);
        }
    });


});

  1. 检查数据库要花多少时间才能返回数据.
  2. 设置Web响应的长度(您可以使用来在web.config中调整JSON响应的大小.)

  1. check how much time your database is taking to returning data.
  2. Set length of web response ( You can adjust the JSON response size in the web.config with ).

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