从使用jQuery ASP.NET的Web方法Ajax调用返回大字符串 [英] Return large string from ajax call using Jquery to Web Method of ASP.NET

查看:211
本文介绍了从使用jQuery ASP.NET的Web方法Ajax调用返回大字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的ASP.NET网站我打电话使用Jquery Web方法如下:

Inside my ASP.NET website I am calling a Web Method using Jquery as follows:

 $.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    data: "{'param1': '" + param1 + "','param2': '" + param2+ "' }",
    dataType: 'json',
    url: "Default.aspx/TestMethod",       
    error: function (jqXHR, textStatus, errorThrown) {
        alert("error: " + textStatus);                     
    },
    success: function (msg) {
        document.getElementById("content").innerHTML = msg.d;
    }
});  

Web方法的定义是:

Web Method Definition is:

[System.Web.Services.WebMethod]
public static String TestMethod(String param1, String param2)
{       
     String to_return = /* result of operations on param1 and param2 */;        
     return to_return;
}

我的结果是包含HTML code的字符串。结果
这是工作完美的,如果在 to_return string是小的。结果
但它给我的错误是:

My result is a String containing HTML code.
It is working perfect if the to_return string is small.
But it is giving me error as:

500内部服务器错误6.22s

500 Internal Server Error 6.22s

我试图在响应使用萤火探索它显示我:

I tried to explore it using FireBug in Response it shows me:

{消息:有一个错误处理请求,堆栈跟踪:,ExceptionType:}

{"Message":"There was an error processing the request.","StackTrace":"","ExceptionType":""}

使用Visual Studio中断点,我抄 to_return 字符串转换成文本文件。该文件的大小变成了:127 KB结果。
可能是什么地方错了?

Using breakpoints in Visual Studio, I have copied the to_return string into a text file. Size of the file became: 127 KB.
What possibly went wrong?

推荐答案

则很可能已经超过了<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.configuration.scriptingjsonserializationsection.maxjsonlength.aspx\">MaxJsonLength,默认为102400个字符,您的字符串较大。您可以增加此限制在web.config中:

Most probably you have exceeded MaxJsonLength, by default it is 102400 characters and your string is bigger. You can increase this limit in web.config:

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

这篇关于从使用jQuery ASP.NET的Web方法Ajax调用返回大字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆