weixin_33675507 2010-12-08 09:16 采纳率: 0%
浏览 39

JQueryMobile-AJAX-JSON解析

Any one help me . I am using the following code for calling web service in jquery mobile. But I am getting the error " Undefined". Please point out me where I done the mistake. THanks in advance.

Coding :

$.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 Output
[ { "type":"Business Profiles", "title":"Lakeview Restaurant", "user":"canwest", "date":"1280144992", "node":{ "nid":"67916", "type":"business_profiles", "language":"", "uid":"1", "status":"1", "created":"1278994293" } } ]

  • 写回答

1条回答 默认 最新

  • weixin_33698823 2010-12-08 09:18
    关注

    You're getting an array back, not a base object - and even then there's no message property that I can see, so it should be:

    alert(msg[0].title);
    

    Or, loop through them all - for example:

    $.each(msg, function(i, profile) {
      alert(profile.type);
      alert(profile.node.nid);
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog