jQuerymobile -ajax -json parsing
-
10-10-2019 - |
質問
誰でも私を助けてくれます。 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); //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"、 "user": "canwest"、 "date": "1280144992"、 "node":{"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