开发者

Get value from MySQL query made with Ajax

I'm running aquery with ajax, this is a part of it:

$count = mysql_query("SELECT C开发者_C百科OUNT(*) FROM Badges WHERE UID = '$user'"); 

$count = mysql_fetch_array( $count );

$count[0]

I want to get the value from $count[0] and asign it to a javascript variable so I can use it on my code. How can I do this?


have you try json_encode() ??

this is how i used to be:

<?php
...
// my logic
...

header("Content-type: application/json");
echo json_encode($count[0]);
?>

and in the javascript :

xmlhttp.onreadystatechange=function(){
  if (xmlhttp.readyState==4 && xmlhttp.status==200){
    var data = eval ("(" + xmlhttp.responseText + ")");
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜