Tuesday, November 22, 2016

Load Only a Section of a Page

Use Case

You want to AJAX load a section of another page on your site onto the current page. Say your eCommerce CMS system creates a dynamic menu of products, but that exists as a subdirectory of your site and you want to use that on the homepage.

#JQuery

$("#mainNav").load("/store #mainNav")

The first param is the URL (only works for same-domain requests!) and the 
second (well, technically it's still part of the first, separated by a space) is a jQuery selector
 of the part to load. Not passing the second selector param will load the entire page. 
There is an optional third parameter, a callback function, which will run when the load is 
complete.

No comments:

Post a Comment

How to Put Google Adsense Below Post Title in Blogger?

Adsense is used by  majority  of expert bloggers for their website monetization because it is a cookie based contextual advertising syste...