简体   繁体   中英

Load new page in div part 2

I have managed to load the new page into the div (thanks to everyone for your help) but it looks pretty bad (got menu bar and logo, but I only wanted the content), so instead I need to load only a div from the new page. I tried a new script but got redirected to the new page. Please help.

<script>
   jQuery(document).ready(function() {
           jQuery('.stil_link_img a').click(function(){
             var x = $(this).attr("href") + "#content_eco";
             jQuery("#new_page").load(x);
             return false;
           });
   });   


</script>
<div id="pachete">
   <?php 
      $result=mysql_query("SELECT* FROM imagini"); 
      while($data=mysql_fetch_row($result)){
                  if( ($data[3]==1)&&($data[2]==2) ){ ?>
   <div class="stil_link_img">
      <a href="<?php echo $data[4];?>" class="poza_efect"><img  src="upload/<?php echo $data[1];?>"></a> 
   </div>
   <?php               }
      }?>
</div>
<div id="new_page">
   //some content which should be replaced with my loaded page
</div>
jQuery(document).ready(function() {
    jQuery('.stil_link_img a').click(function(){
      var $pageContent = jQuery('<div/>').load($(this).attr("href"));
      jQuery("#new_page").html(jQuery("#content_eco",$pageContent).html());
      return false;
    });
});  

I assume #content_eco is the divisions ID in the new page(the url from href attribute).

or you can load just the content from the url and avoid the link postback as

<script>
   jQuery(document).ready(function() {
           jQuery('.stil_link_img a').click(function(){
             var x = $(this).attr("rel") + " #content_eco";
             jQuery("#new_page").load(x);
             return false;
           });
   });
</script>
<div id="pachete">
   <?php 
      $result=mysql_query("SELECT* FROM imagini"); 
      while($data=mysql_fetch_row($result)){
                  if( ($data[3]==1)&&($data[2]==2) ){ ?>
   <div class="stil_link_img">
      <a href='#' rel="<?php echo $data[4];?>" class="poza_efect"><img  src="upload/<?php echo $data[1];?>"></a> 
   </div>
   <?php               }
      }?>
</div>
<div id="new_page">
   //some content which should be replaced with my loaded page
</div>

Hope this helps you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM