
请各位大侠帮我看看这段代码我错在哪里 我从PHP取数据,传到JS执行的时候,发现JS根本都没有执行
php代码<?phperror_reporting(0);mysql_connect(“数据库","username","password")ordie("不能链接到数据...
php代码
<?php
error_reporting(0);
mysql_connect(“数据库","username","password") or die("不能链接到数据库服务器".mysql_error());
mysql_select_db("showslow");
$sql2 = "select a.o from yslow2 a order by a.timestamp desc limit 12";
$query2=mysql_query($sql2);
while ($result2=mysql_fetch_array($query2))
{
$foodsPic[]=$result2[o];
}
$data1 = json_encode($foodsPic);
// echo $data1;
?>
js代码
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
<script>
$(function()
{
$.ajax({
type:'get',
url:'localhost/g.php',
cache:false,
dataType:'json',
success:function(data1){
alert(data1);
}
});
});
</script> 展开
<?php
error_reporting(0);
mysql_connect(“数据库","username","password") or die("不能链接到数据库服务器".mysql_error());
mysql_select_db("showslow");
$sql2 = "select a.o from yslow2 a order by a.timestamp desc limit 12";
$query2=mysql_query($sql2);
while ($result2=mysql_fetch_array($query2))
{
$foodsPic[]=$result2[o];
}
$data1 = json_encode($foodsPic);
// echo $data1;
?>
js代码
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
<script>
$(function()
{
$.ajax({
type:'get',
url:'localhost/g.php',
cache:false,
dataType:'json',
success:function(data1){
alert(data1);
}
});
});
</script> 展开
1个回答
展开全部
函数没有执行,你的自执行函数写的有问题,代码是自己写的?
追问
是我自己写的,哪里有问题,麻烦你告诉我下
追答
我对jq不是特别了解,但是$.json()是js传值给php吧--
你现在是php传值给js,所以方法应该错了,你确认一下。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询