ajax通过POST方式调用.net的webService时,数据过长时服务器返回500错误
同事通过post方式通过WebService提交图片时,图片大小超过50KB以上时服务器就返回500错误,50KB以下一切正常。网上查了资料,通过设置jsonSerialization maxJsonLength的值问题解决
<!--功能说明:Ajax调用WebService --> <script type="text/javascript"> function test(){
$.ajax({ type: "POST", contentType: "application/json;charset=utf-8", url: "http://www.xxxx.org/test.asmx/TestMethod", data:"{a:12345,b:'imgData.base64'}",
success: function (response) { alert("成功"); }, error: function (msg) { alert("错误:" + msg); } })
} </script>
在web.config的configuration节中添加如下设置
<configuration> <system.web.extensions> <scripting> <webServices>
<!-- maxJsonLength:单位为字节(byte) -->
<jsonSerialization maxJsonLength="1024000"/> </webServices> </scripting> </system.web.extensions> </configuration> |