【发布时间】:2013-03-27 14:09:35
【问题描述】:
我想从 PHP 检索一组数组到 ajax。我的代码没有返回任何东西,有人可以帮助我如何将值从 PHP 检索到 ajax。如果我不在 mysql_fetch 中创建数组,它将从数据库中检索最后一个值并将其传递给 ajax 函数。我想获得全部价值。我该怎么做?
AJAX 代码:
<script>
//Global Variables
var channel;
function overall(){
$(".one").show();
$(".two").hide();
$(".three").hide();
$(".four").hide();
window['channel']="overall";
$.ajax({
type:"GET",
url:"dash2.php",
data:{channel:channel},
dataType:'json',
success:function(data){
console.log(data.a);
console.log(data.b);
console.log(data.c);
}
});
}
</script>
PHP 代码:
<?php
error_reporting(0);
$channel=$_GET['channel'];
$host="192.168.0.29";
$username="root";
$password="root";
$dbname="realcl";
mysql_connect($host,$username,$password)
OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname);
$query = 'select * from '.$channel;
$masterresult = mysql_query($query);
$success[];
$timeout[];
$fail[];
while($row1 = mysql_fetch_array($masterresult))
{
$success[]=$row1[1];
$timeout[]=$row1[2];
$fail[]=$row1[3];
}
echo json_encode(array("a"=>$success,"b"=>$timeout,"c"=>$fail));
?>
【问题讨论】:
-
@undefined 这是完全重复的
-
这个问题是关于在 ajax 中使用数组没有解决类型问题
-
当有人以
dual where 0; drop database realcl;--输入channel时会发生什么
标签: php javascript ajax jquery