JQueryMobile - AJAX - разбор JSON - PullRequest
       9

JQueryMobile - AJAX - разбор JSON

1 голос
/ 08 декабря 2010

Кто-нибудь, помогите мне.Я использую следующий код для вызова веб-службы в jquery mobile.Но я получаю ошибку «Не определено».Пожалуйста, укажите мне, где я совершил ошибку.Заранее спасибо.

Кодирование:

$.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
[{"type": "Business Profiles", "title ":" Ресторан Lakeview "," user ":" canwest "," date ":" 1280144992 "," node ": {" nid ":" 67916 "," type ":" business_profiles "," language ":""," uid ":" 1 "," status ":" 1 "," созданный ":" 1278994293 "}}]

1 Ответ

2 голосов
/ 08 декабря 2010

Вы получаете обратно массив, а не базовый объект - и даже в этом случае я не вижу свойства message, поэтому оно должно быть:

alert(msg[0].title);

Или перебрать их все - например:

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