JQueryMobile - Ajax - JSON SARSING
-
10-10-2019 - |
Вопрос
Кто -нибудь мне поможет. Я использую следующий код для вызова веб -службы в 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 Restaurant", "Пользователь": "CanWest", "Date": "1280144992", "Узел": {"NID": "67916", " введите ":" business_profiles "," language ":", "uid": "1", "status": "1", "Создан": "1278994293"}}
Решение
Вы получаете массив назад, а не базовый объект - и даже тогда нет message
свойство, которое я вижу, так что это должно быть:
alert(msg[0].title);
Или, проберите их всех - например,:
$.each(msg, function(i, profile) {
alert(profile.type);
alert(profile.node.nid);
});
Не связан с StackOverflow