javascript - Load content of an external page to a div? -
this main page
<html> <head> <title></title> <style> #exp{ height: 100%; width:100%; position: absolute; left:0; top:0; background:#00ff00; } </style> <script src="scripts/jquery.js"></script> <script> $(function(){ $("#exp").load('aboutus.html'); }) </script> </head> <body> <div id="exp"> </div> </body> </html>
i want load content page aboutus.html content in page is
<div style="height:100%;width:100%;position:absolute;left:0px;top:0px">hai</div>
i tried load,get,.html etc none of them working. don't want include php
methods tried
$("#exp").load('aboutus.html'); $("#exp").get('aboutus.html'); $("#exp").html(url(aboutus.html'));
one way using ajax call using jquery.
just wrap page json call function. detail see below
main page code
<html> <head> <title></title> <style> #exp { height: 100%; width:100%; position: absolute; left:0; top:0; background:#00ff00; } </style> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script> jquery(function(){ jquery.getjson('about.php?callback=?',function(data){ if(data.status == 'success') { jquery('#exp').html(data.html); } }); }) </script> </head> <body> <div id="exp"> </div> </body> </html>
about.php page
<?php $html .=<<<html <div style="height:100%;width:100%;position:absolute;left:0px;top:0px">hai</div> html; $strippedhtml = str_replace(array("\r\n", "\r", "\n", "\t"), ' ', $html); echo $_get['callback'] . '({"status":"success", "html":"' . addslashes(trim($strippedhtml)) . '"})'; ?>
Comments
Post a Comment