Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading specific div from jquery $GET requested page?

I have something like this:

<a href="#" id="lol">LOL</a>        
<script type="text/javascript">

$('#lol').click(function(){ 
  $.get("<?php echo $host.'/index.php'?>", 
  { page: "topobjekt", index: "<?php echo $l;?>", pages: "<?php echo $pg+1;?>" },
  function(data){
           $('#primary_content').html(data);
                });
        });

Is it possible to load specific div(for instance #secondary_content) from my GET requested php page and load it into #primary_content target?

like image 638
Matija Milković Avatar asked May 27 '26 10:05

Matija Milković


2 Answers

Why not modify your PHP script to handle the AJAX request specifically? You will save wasted bandwidth loading a whole page when you know all you need is one div.

Add a get variable and check for this to determine context.

like image 199
deed02392 Avatar answered May 30 '26 04:05

deed02392


Change this line:

$('#primary_content').html(data);

To this:

$('#primary_content').html(data.find("#secondary_content"));
like image 30
Rory McCrossan Avatar answered May 30 '26 03:05

Rory McCrossan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!