Possible Duplicate:
Can I set an unlimited length for maxJsonLength in web.config?
I have a script in my .aspx page that is sending info to the back-end .cs page. Concept is simple and worst for most occasions, except when data is too large. How can I increase the capacity of what the "data" variable can hold without modifying web.config? Please see code below.
.ASPX
<script type="text/javascript">
$(document).ready(function () {
var note = "";
for (var i = 0; i < 200000; i++)
note = note + "x";
$.ajax({
type: "POST",
url: "GroupDetailsDisplayPlus.aspx/UpdateRecord",
data: "{note: \"" + note + "\"}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
var response = msg.d;
alert("success");
}
error: function (request, status, thrownError) {
//alert(request.thrownError); // short version
alert(request.responseText); // long version
}
});
});
</script>
.CS
[System.Web.Services.WebMethod]
public static string UpdateRecord(string note)
{
return note;
}
This code is simplified and my purpose is to store this large string in a database (code ommited). If I set the for loop to only do 100,000 cycles this works. However increasing it to 200,000 cycles fails with an error message:
{"Message":"Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.\r\nParameter name: input","StackTrace": at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n at System.Web.Script.Serialization.JavaScript Serializer.Deserialize[T](String input)\r\n at System.Web.Script.Service.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.ArgumentException"}
Thank you for any and all help.
Try this:
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="500000">
</jsonSerialization>
</webServices>
</scripting>
</system.web.extensions>
and this:
<system.web>
<httpRuntime requestValidationMode="2.0" executionTimeout="600" maxRequestLength="2000000" />
<system.web>
or divide your data and send part by part:
var portionIndex = 0;
var porions = new Array();
for(i = 0; i < 5; i++)
{
var note = '';
for (var j = 0; j < 40000; j++) note += "x";
portions.push(note);
}
SendPortion();
function SendPortion()
{
$.ajax({
type: "POST",
url: "GroupDetailsDisplayPlus.aspx/UpdateRecord",
data: {porionsCount: porions.length, portion: porions[portionIndex] },
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
portionIndex++;
if(portionIndex < porions.length)
SendPortion();
}
error: function (request, status, thrownError) {}
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With