I am using an ajax PageMethod to call an asp.net webmethod. From there I'm trying to pass a lot of XML back to a callback javascript function.
Currently I just convert the XML into a string and pass it in that format. But it seems that if the string is too long it causes an error.
Here's the VB:
<System.Web.Services.WebMethod()> _
Public Shared Function getXML() As String
Dim strXML
strXML=getLoadsOfXML().InnerXml;
Return strXML
End Function
Here's the javascript:
function loadGrid(){
PageMethods.getXML(myCallback);
}
//This function doesn't get called if strXML is too long
function myCallback(strXML){
useXML(strXML);
}
Here's the error:
Microsoft JScript runtime error: Sys.Net.WebServiceFailedException: The server method 'getXML' failed with the following error: System.InvalidOperationException-- Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
So my question is: Is there a better way to pass the XML from VB to javascript, or a way to allow large strings to be passed without error?
This question appears to be what you want, but according to the answer the default value is 4MB. I would look into if you really want to be returning so much data to the client (just imagine someone on a very slow internet connection).