属性从 2.0 更改为 3.5

发布于 2024-10-06 20:28:22 字数 255 浏览 0 评论 0原文

我有一个看起来像这样的方法:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

决绝 2024-10-13 20:28:22

您必须导入 System.Web.Script.Services

然后,尝试添加此属性:

<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Xml)> _

您如何调用 Web 方法?通过JavaScript?

You'll have to import System.Web.Script.Services

Then, try adding this attribute:

<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Xml)> _

How are you calling the web method? Through javascript?

画尸师 2024-10-13 20:28:22

我们有类似的问题。通过Webmethod和jquery ajax调用的基本设置,2.0它返回一个字符串(在js中类型string)或字符串数​​组(在js中类型object),在3.5中它总是返回一个对象,并且返回时实际返回的数据在.d下像字符串或字符串数​​组这样的原语。

到目前为止,我最好的解决方案是使用 javascript 方法来检查 .d。

    function getResponse(r){
        if(r.d!=null){
            return r.d;
        }else{
            return r;
        }
    }

我必须支持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.

    function getResponse(r){
        if(r.d!=null){
            return r.d;
        }else{
            return r;
        }
    }

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文