不确定这可能是重复的...请帮助我解决这个问题
我试图获取 3 个 Mysql 值到 jquery ajax 函数。 但我无法显示这些值。 我已经使用了各种帖子中描述的许多方法。 但对我来说没有什么是匹配的。
下面是我的php页面
$equipm = array();
$service = array();
$facility = array();
$result = array();
$equip_sel = "select * from equipment";
$run_equip = mysqli_query($con,$equip_sel);
while($rowe =mysqli_fetch_assoc($run_equip))
{
$equipm[] = $rowe;
}
$serv_sel = "select * from services";
$run_serv = mysqli_query($con,$serv_sel);
while($rows =mysqli_fetch_assoc($run_serv))
{
$servc[] = $rows;
}
$faci_sel = "select * from specility ";
$run_fac = mysqli_query($con,$faci_sel);
while($rowf =mysqli_fetch_assoc($run_fac))
{
$facility[] = $rowf;
}
//$result[0]=$equipm;
//$result[1]=$servc;
//$result[2]=$facility;
$result=array('equipment'=>array($equipm), 'services'=> array($servc), 'facility'=> array($facility));
echo json_encode($result);
下面是我的jquery,
<script type='text/javascript'>
$(document).ready(function(){
/* call the php that has the php array which is json_encoded enter code here*/
$.ajax({
type:"POST",
url: "ajax2.php",
datatype: "json",
success: function(data) {
alert(data[0]);
});
}
});
});
</script>
以上结果是输出表中的每一个字符。
请在这里提供帮助。 每次返回一个字符。
由于右括号和括号,jquery 中存在语法错误。这是对我有用的固定版本。
<script type='text/javascript'>
$(document).ready(function(){
/* call the php that has the php array which is json_encoded enter code here*/
$.ajax({
type:"POST",
url: "ajax2.php",
datatype: "json",
success: function(data) {
alert(data[0]);
}
});
});
</script>