i am a newbie and am stuck at retrieving json data.
我是一个新手,我被困在检索json数据。
following is my index.php :
下面是我的指数。php:
<script type="text/javascript" src="jquery-1.3.2.min_2.js">
$("document").ready(function() {
$.getJSON("data.php",function(jsondata){
$("#content").html(jsondata[0].content);
});
});
</script>
</head>
<body>
<div id="content"></div>
<div class="lg"></div>
</body>
in my data.php i am using the standard way of encoding and sending the data:
在我的数据。我正在使用标准的编码和发送数据的方式:
// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
$row = mysql_fetch_row($result);
$jsonserver[$i] = $row;
}
echo json_encode($jsonserver);
header('Content-type: application/json');
mysql_free_result($result);
// close connection
mysql_close($con);
i am using mysql database. when i open localhost/data.php the json data is shown on the browser. but in case if i open localhost/index.php i donot get any desired output. Please explain. Thanks!
我正在使用mysql数据库。当我打开localhost /数据。php浏览器显示json数据。但如果我打开localhost/index。我没有得到任何期望的输出。请解释一下。谢谢!
2 个解决方案
#1
0
Hey, u didn't close script tag properly
嘿,你没有关闭脚本标签
try
试一试
<script type="text/javascript" src="jquery-1.3.2.min_2.js"></script>
<script type="text/javascript">
$("document").ready(function() {
$.getJSON("data.php",function(jsondata){
$("#content").html(jsondata[0].content);
});
});
</script>
#2
1
you need to put all headers before any 'echo's on the page
你需要把所有的标题放在页面上的任何“echo”之前
so:
所以:
header('Content-type: application/json');
echo json_encode($jsonserver);
#1
0
Hey, u didn't close script tag properly
嘿,你没有关闭脚本标签
try
试一试
<script type="text/javascript" src="jquery-1.3.2.min_2.js"></script>
<script type="text/javascript">
$("document").ready(function() {
$.getJSON("data.php",function(jsondata){
$("#content").html(jsondata[0].content);
});
});
</script>
#2
1
you need to put all headers before any 'echo's on the page
你需要把所有的标题放在页面上的任何“echo”之前
so:
所以:
header('Content-type: application/json');
echo json_encode($jsonserver);