从 webmethod 返回 XML
我正在使用 ajax PageMethod 来调用 asp.net webmethod。从那里我尝试将大量 XML 传递回回调 javascript 函数。
目前,我只是将 XML 转换为字符串并以该格式传递。但似乎如果字符串太长就会导致错误。
这是 VB:
<System.Web.Services.WebMethod()> _
Public Shared Function getXML() As String
Dim strXML
strXML=getLoadsOfXML().InnerXml;
Return strXML
End Function
这是 javascript:
function loadGrid(){
PageMethods.getXML(myCallback);
}
//This function doesn't get called if strXML is too long
function myCallback(strXML){
useXML(strXML);
}
这是错误:
Microsoft JScript 运行时错误:Sys.Net.WebServiceFailedException: 服务器方法“getXML”失败并出现以下错误: System.InvalidOperationException--序列化期间出错或 使用 JSON JavaScriptSerializer 进行反序列化。的长度 字符串超出了 maxJsonLength 属性上设置的值。
所以我的问题是:是否有更好的方法将 XML 从 VB 传递到 javascript,或者允许大字符串无错误地传递?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个 问题 似乎是您想要的,但根据答案,默认值为 4MB。我会调查一下您是否真的想要向客户端返回如此多的数据(想象一下某人的互联网连接速度非常慢)。
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).