属性从 2.0 更改为 3.5
我有一个看起来像这样的方法:
<WebMethod()> _
Public Function Search(ByVal q As String) As String
从.net 2.0更新到3.5似乎已经打破了这个。
我们对返回的值执行 data.split() ,这会生成一个错误 - 看起来返回的值现在是一个 json 结构,而不是一个简单的字符串。
有没有办法恢复到之前的行为?
I have a method that looks like:
<WebMethod()> _
Public Function Search(ByVal q As String) As String
Updating from .net 2.0 to 3.5 appears to have broken this.
We're doing data.split() on the value returned, and that's generating a error - it looks like the value returned is now a json structure, not a simple string.
Is there a way to revert to the prior behavior?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须导入 System.Web.Script.Services
然后,尝试添加此属性:
您如何调用 Web 方法?通过JavaScript?
You'll have to import System.Web.Script.Services
Then, try adding this attribute:
How are you calling the web method? Through javascript?
我们有类似的问题。通过Webmethod和jquery ajax调用的基本设置,2.0它返回一个字符串(在js中类型string)或字符串数组(在js中类型object),在3.5中它总是返回一个对象,并且返回时实际返回的数据在.d下像字符串或字符串数组这样的原语。
到目前为止,我最好的解决方案是使用 javascript 方法来检查 .d。
我必须支持2.0和3.5的过渡呼吁,并且不想花费太多精力,因为2.0很快就会消失。
但我宁愿有更好的解决方案。
We had a similar issue. With the basic setup of Webmethod and jquery ajax call with 2.0 it returns a string (type string in js) or string array (type object in js), in 3.5 it always returns an object and the actual data returned is under .d when returning a primitive like a string or string array.
My best solution so far was a javascript method to check for .d.
I have to support both the 2.0 and 3.5 calls for the transition and would rather not have to expend too much energy as 2.0 will be gone soon.
But I would rather a better solution.