在调用返回json格式列表<string> </string>的.ajax方法时得到未定义的json结果

时间:2013-11-22 05:29:04

标签: java javascript jquery ajax json

我得到的是未定义的结果而不是列表数组。这是我的代码

      $.ajax({
                type: "POST",
                url: "DeviceInfo.aspx/GetDeviceValues",
                data: {},
                async:true,
                contentType: "applciation/json; charset=utf-8",
                datatype: "json",
                success: function (msg) { var arr = msg.d; alert(arr); for (var i in arr) { alert(i) } },
                error: function (x, e) {
                    alert("The call to the server side failed. " + x.responseText);
                }             });

这是我正在呼叫的网络方法

[WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
    public static List<string> GetDeviceValues()
    {
        System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
        List<string> Row = new List<string>();
        Row.Add("First Device ");
        Row.Add("IMEI No Is 22323233");
        Row.Add("UI No is 23232");
        Row.Add("Msg No is 12");
        Row.Add("Active is status is true");
        Row.Add("InActive status is false");
        return Row;

    }

当我看到它显示为未定义的msg.d或msg值时,我的代码出了什么问题。

1 个答案:

答案 0 :(得分:0)

尝试使用

$.each(result, function (index, item) {
    ////try something in alert(item.d);
});

并修改您的错误,使其显示更多指定错误

error: function(XMLHttpRequest, textStatus, errorThrown){
alert(errorThrown);
}