Javascript JQueryMobile-AJAX-JSON解析
谁来帮我。我使用以下代码在jquery mobile中调用web服务。但我得到的错误是“未定义”。请指出我犯错误的地方。提前谢谢 编码:Javascript JQueryMobile-AJAX-JSON解析,javascript,ajax,jquery,jquery-mobile,Javascript,Ajax,Jquery,Jquery Mobile,谁来帮我。我使用以下代码在jquery mobile中调用web服务。但我得到的错误是“未定义”。请指出我犯错误的地方。提前谢谢 编码: $.ajax({ type: 'POST', url: "http://jquery.sample.com/nodes.json", data: ({search_keys :theName}), dataType: 'json', timeout: 5000, success: function(msg) { console.log(msg);
$.ajax({
type: 'POST',
url: "http://jquery.sample.com/nodes.json",
data: ({search_keys :theName}),
dataType: 'json',
timeout: 5000,
success: function(msg)
{
console.log(msg); //here, I can see the result in browser.
alert(msg.message); //Undefined Error
},
error: function(xhr, status, errorThrown)
{
alert(status + errorThrown);
}
});
JSON输出[ { “类型”:“业务概要文件”, “名称”:“湖景餐厅”, “用户”:“canwest”, “日期”:“1280144992”, “节点”:{ “nid”:“67916”, “类型”:“业务概况”, “语言”:“, “uid”:“1”, “状态”:“1”, “已创建”:“1278994293” } }
]您得到的是一个数组,而不是一个基本对象-即使这样,我也看不到
消息
属性,因此它应该是:
alert(msg[0].title);
或者,将它们全部循环—例如:
$.each(msg, function(i, profile) {
alert(profile.type);
alert(profile.node.nid);
});