[英]Getting undefined json result on calling .ajax method which return json format list<string>
I am getting undefined result instead of list array. 我得到未定义的结果,而不是列表数组。 Here is my code
这是我的代码
$.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);
} });
Here is the webmethod i am calling 这是我正在打电话的网络方法
[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;
}
When i see the msg.d or msg value it showing as undefined, what's wrong with my code. 当我看到msg.d或msg值显示为未定义时,我的代码出了什么问题。
try to use 尝试使用
$.each(result, function (index, item) {
////try something in alert(item.d);
});
and modify your error to look like this to fetch more specify error 并修改您的错误,使其看起来像这样以获取更多指定错误
error: function(XMLHttpRequest, textStatus, errorThrown){
alert(errorThrown);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.