简体   繁体   中英

Loading a part of a page with ajax

I want a part of another page with Ajax Loading. When you click on a button. I have a page. But, i want load only the .section div in the page. When i click on the button. Than only the .section page in the other page must be load.

But, how can i load with ajax / jquery. Only a div from a other page.

You can do this without ajax using jQuery's load method. With this, you can load the content returned into your #div_id or body . Here is an example to load your content into your page's body ;

$("#your_button_id").click(function() {
  var myUrl = "yourpage.html #div_id_having_data";
  $("body").load(myUrl);
  return false;
});

Take a look at the jQuery Ajax/load documentation

If i have understood your question properly, then this would be the solution,

On button click load the whole page (.section should be hidden). Then on click of the other button just toggle the .section div.

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