通过ajax在javascript中解析Web服务响应时出错

时间:2012-05-21 21:39:44

标签: c# asp.net ajax web-services response

我通过一个看起来像

的ajax调用来调用Web服务
$.ajax({
         cache: false,
         type: 'POST',             
         url: 'renderDisplay.asmx/displayElements',
         dataType: 'json',
         data: object,
         success: function () {
             alert ("success"); },
         error: function (response) {                                    
             alert("error: " +  response.responseText);}
});

我的网络服务功能 -

JavaScriptSerializer serializer = new JavaScriptSerializer();
Dictionary<string, string> temp = new Dictionary<string, string>();
temp.Add("boston", "mass");
string json = serializer.Serialize((object)temp);
return json;

我得到的错误 -

注意:开头括号“&lt;”已被放在括号中,因为否则将2行作为实际代码

error: (<)?xml version="1.0" encoding="utf-8"?>
(<)string xmlns="http://tempuri.org/">{"boston":"mass"}</string>

1 个答案:

答案 0 :(得分:0)

在我看来,您的Web服务实际上正在返回用XML包装的JSON。

此主题可能有所帮助:

ASP.NET JSON web service always return the JSON response wrapped in XML