1

誰もが私を助けてくれます。jquerymobileで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" 、"type": "business_profiles"、 "language": ""、 "uid": "1"、 "status": "1"、 "created": "1278994293"}}]

4

1 に答える 1

2

ベースオブジェクトではなく、配列が返されます。それでも、message表示できるプロパティがないため、次のようになります。

alert(msg[0].title);

または、それらすべてをループします-例:

$.each(msg, function(i, profile) {
  alert(profile.type);
  alert(profile.node.nid);
});
于 2010-12-08T09:18:35.340 に答える