我得到的是未定义的结果而不是列表数组。这是我的代码
$.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值时,我的代码出了什么问题。
答案 0 :(得分:0)
尝试使用
$.each(result, function (index, item) {
////try something in alert(item.d);
});
并修改您的错误,使其显示更多指定错误
error: function(XMLHttpRequest, textStatus, errorThrown){
alert(errorThrown);
}