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>
