$.jquery ajax returned data (json) displays as 'undefined'

前端 未结 1 1414
野性不改
野性不改 2021-01-05 09:45

Here I have a simple php script which displays some values from a database in json format.

$source = $_GET[\'source\'];

$query = mysql_query(\"SELECT * FROM         


        
相关标签:
1条回答
  • 2021-01-05 10:27

    Your json string has an array format. You need to access the json object properties like this

    title = data[0].title;
    alert(title);
    
    date = data[0].date;
    alert(date);
    
    time = data[0].time;
    alert(time);
    

    If you control the json format and an array is not necessary, use a json object with this format.

    {"title":"Torus","date":"2012-04-04","time":"23:06:14"}
    

    In this case you can keep your code as it is now.

    0 讨论(0)
提交回复
热议问题