show_page.php:
<?
session_start();
include("includes/function.php");
$static = mysql_query("SELECT * FROM fb_pages WHERE user_id = '$_SESSION[user_id]' AND page_value = '1' ") or die(mysql_error());
while($stat = mysql_fetch_array($static)) {
$page = $stat['page_name'];
echo json_encode($page);
exit();
}
ob_and_flush();
?>
and js code:
<script type="text/javascript">
$.ajax({
type: "POST",
url: "show_page.php",
dataType: "JSON", //tell jQuery to expect JSON encoded response
success: function(response) {
$('#page').html(response);
}
});
</script>
I like show the result in <div id="page"></div> .
If run this code, the result is one page, and always one page, but if I delete in show_page.php , exit(); then result is good, show all page, but don't show webpage, I think, then may json. What this problem??
mysql_query. It's a deprecated interface that's being removed from PHP. Also, you should be very careful about properly escaping SQL values or you will end up with nasty SQL injection bugs. You should not be inserting arbitrary data from$_SESSIONinto your queries.mysql_*functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.