0

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?

4

2 回答 2

0

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

然后,尝试添加此属性:

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

你如何调用网络方法?通过javascript?

于 2010-12-08T17:54:26.870 回答
0

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

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

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

我必须同时支持 2.0 和 3.5 过渡的呼吁,并且宁愿不必花费太多精力,因为 2.0 很快就会消失。

但我宁愿有更好的解决方案。

于 2010-12-08T21:28:00.633 回答