.NET Web服务为ajax调用返回的奇数<string> </string>响应

时间:2012-03-13 18:36:49

标签: jquery asp.net web-services

我是ASP.NET新手并与我们的一个内部开发人员合作,但他们现在已经出局了,我有一个网络服务要消费,但我得到了一个我以前没见过的结果:

数据回复如下:

<string xmlns="https://domain.com">
"<option>asdas</option><option>asdas</option><option>asdas</option>
 <option>asdas</option><option>asdas</option><option>asdas</option>"
</string>

我也可以访问.NET,我看到以下内容:

[WebMethod(true)]
public string GetProductTypesByProductLine(string productLine, int cono)
{
    var results = service.GetProductTypes(productLine, cono);
    StringBuilder sb = new StringBuilder(1000);
    foreach (var result in results)
    {
        sb.Append(string.Format("<option value='{0}'>{1}</option>", result, result));
    }

    return sb.ToString();
}

有人能指出我正确的方向吗?我只是希望快速简单的HTML输出,所以我可以利用if jQuery html ajax调用。

2 个答案:

答案 0 :(得分:1)

由于您希望返回一个字符串,请改用HTTP处理程序。 Web服务将其响应打包为XML或JSON。请参阅How To Create an ASP.NET HTTP Handler by Using Visual C# .NET以帮助您入门。

然后,您可以使用jQuery .load()函数将文本添加到HTML元素中。

答案 1 :(得分:0)

检查您是否按以下方式调用了您的网络方法:

$.ajax({
      "type": "POST",
       "dataType": 'json',
       "contentType": "application/json; charset=utf-8",
        //etc
 });