i am a newbie and am stuck at retrieving json data.
following is my index.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!
json_encode($jsondata)output?index.php? Do you have an element withid="content"?<?phpopening tag, because this will cause PHP to send the default headers most common would be:Content-type: text/html.