Load a page using jQuery & AJAX

I have a list of dynamic links on page A and div where I want to load content from another dynamically generated page B based on PHP variables.

<a href="loader.php?id=1">Link 1</a> <a href="loader.php?id=2">Link 2</a> <a href="loader.php?id=3">Link 3</a> 

This script successfully loads external content from the loader.php page using the jQuery script below in the #ajaxContent div.

 $(document).ready(function(){ $("a").click(function(){ $.ajax({ url:$(this).attr("href"), success: function(response) { $("#ajaxContent").html(response); } }); return false; }); }); 

My question is how to load content from a named div element on the loader.php page using the script modification above? The reason for this is to show content called using Ajax in its correct context on a natural URL, for example: href = "loader.php? Id = 2, which is correct but not enabled by JavaScript / SEO practice, I suppose.

Update: Explosive pills are almost there! thank you very much.

Working code.

 $(".switchMe li a").click(function(){ $.ajax({ url:$(this).attr("href"), success: function(response) { // $("#ajaxContent").html(response); $("#ajaxContent").html($(response).find("#imageInfo")); } }); return false; }); 

Thanks jimmy

+6
source share
2 answers

You can use .load as in

 $("#ajaxContent").load($(this).attr("href") + " #named-div"); 

Otherwise, analyze the response yourself:

 $("#ajaxContent").html($(response).find("#named-div")); 
+10
source

Checkout jQuery . load () method.

+1
source

Source: https://habr.com/ru/post/953175/


All Articles