我在访问ajax调用返回的json值时遇到问题。
电话如下:
$.ajax({
type: \'POST\',
data: \'user_id=\' + user.user_id + \'&user_login=\'+ user.user_login,
//dataType: \'json\',
url: \'http://###/user-stats.php\',
success: function(data){
alert(data);
//alert(data.games_won[0][\'winner_id\']);
//console.log(data);
if(data) {
$(\'#hand-stats-display\').html(data);
//$.mobile.changePage( "#user-home", { transition: "fade"} );
}else{
$(\'.messages\').html("No stats available at this time... Please try again later.");
//alert(data);
}
},
error: function(){
//console.log(data);
alert(\'Ajax Login Request ✗\');
}
});
以下是PHP:
$myrows[\'hands_won\'] = $wpdb->get_results( "SELECT * FROM wp_winners WHERE user_id=" . $user_id );
if ( $myrows )
{
//echo(\'Rows Exist ✓\');
//echo "List of {$meta_key1} posts, sorted by {$meta_key2}";
foreach ( $myrows as $id )
{
$creds[]=$id;
//echo(\'MyRows: \' . $myrows[id]);
}
}
//echo "Winner ID:" .$myrows[0]->win_id;
//echo "Winner 2 ID:" .$myrows[1]->win_id;
echo json_encode($creds);
它返回一个json对象,如:
[{"win_id":"1","user_id":"1","game_id":"1"},{"win_id":"2","user_id":"1","game_id":"2"}]
我似乎无法使用我正在使用的javascript访问这些内容。如有任何建议,我们将不胜感激。