php - AJAX loading whole page instead of part of the page to load data from database -
i want show image in iframe using ajax full page loading in every 5 seconds want content load if there change in status table.
i think have section. may need transfer php code or need change on div. if please me ?
main.php
<!doctype html> <html> <head> <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> <script> $(function(){ function status(){ $.ajax({ type: "get", url: "main.php", success: function(data){ $('div.divgranite').html(data); } }); }; settimeout(status, 5000); }); </script> </head> <body> <div id="divgranite"> <?php //connect database $connection = mysqli_connect("localhost", "root", "pass"); if (!$connection) { die("error: " . mysqli_error()); } $db_select = mysqli_select_db($connection, "database"); if (!$db_select) { die("error: " . mysqli_error()); } $appid = "select * table state= '1' "; $result = mysqli_query($connection,$appid); while ($row = $result->fetch_assoc()) { $currentid = $row['id']."<br>"; } ?> </div> <div id="display1"> </div> </body> <?php if($currentid != $displayid){ function loadunload($id) { $connection = mysqli_connect("localhost", "root", "pass"); if (!$connection) { die("error: " . mysqli_error()); } $db_select = mysqli_select_db($connection, "usr_web26_1"); if (!$db_select) { die("error: " . mysqli_error()); } switch ($id) { case $id == 1: echo '<div>'; echo '<iframe src="../imageview/index.php" id="imgiframe" style="position:fixed; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden; z-index:999999;"></iframe>'; echo '</div>'; break; case $id == 2: echo '<div>'; echo '<iframe src="../videoview/index.php" id="imgiframe" style="position:fixed; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden; z-index:999999;"></iframe>'; echo '</div>'; break; default: echo "wrong id"; break; } } ?> </html>
this main.php returning hole main.php including head-tag , putting divgranite, if want ajax request return part of main.php produces need make 2 files:
- main.php - rendering default page
- ajax.php - rendering iframe only
this open call ajax.php instead , give wanted result ajax.php this,
<?php //connect database $connection = mysqli_connect("localhost", "root", "pass"); if (!$connection) { die("error: " . mysqli_error()); } $db_select = mysqli_select_db($connection, "database"); if (!$db_select) { die("error: " . mysqli_error()); } $appid = "select * table state= '1' "; $result = mysqli_query($connection,$appid); while ($row = $result->fetch_assoc()) { $currentid = $row['id']."<br>"; } if($currentid != $displayid) { function loadunload($id) { $connection = mysqli_connect("localhost", "root", "pass"); if (!$connection) { die("error: " . mysqli_error()); } $db_select = mysqli_select_db($connection, "usr_web26_1"); if (!$db_select) { die("error: " . mysqli_error()); } switch ($id) { case $id == 1: echo '<div>'; echo '<iframe src="../imageview/index.php" id="imgiframe" style="position:fixed; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden; z-index:999999;"></iframe>'; echo '</div>'; break; case $id == 2: echo '<div>'; echo '<iframe src="../videoview/index.php" id="imgiframe" style="position:fixed; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden; z-index:999999;"></iframe>'; echo '</div>'; break; default: echo "wrong id"; break; } }
Comments
Post a Comment