开发者

Get value from MySQL query made with Ajax

开发者 https://www.devze.com 2023-04-03 08:16 出处:网络
I\'m running aquery with ajax, this is a part of it: $count = mysql_query(\"SELECT C开发者_C百科OUNT(*) FROM Badges WHERE UID = \'$user\'\");

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

精彩评论

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