How to access Product module output with jquery [solved]

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
User avatar
chrisbt
Dev Team Member
Dev Team Member
Posts: 203
Joined: Sun Sep 05, 2010 6:11 am

How to access Product module output with jquery [solved]

Post by chrisbt »

I am attempting my first foray in ajax functionality. I have managed to achieve the desired result, but would like to know if there is a better way to achieve this.

I want to reload a product shortlist/wishlist from the Products module. The way I have achieved this initially is to create a blank template and dummy page 'tmp/shortlist.html' that just contains the output of:
{Products summarytemplate="Product_Thumbnails" productlist=$shortlist_ids pagelimit="6"}

Then using jquery I reload the html snippet when necessary with:

Code: Select all

$('#shortlist_content').load('tmp/shortlist.html');
While this works just fine. (I was amazed how easy it was!) I suspect there must be a more elegant way to get to the module output from javascript than having to create a dummy page. I am probably missing something pretty obvious, but can't find a solution so far in the forums.

Thanks

Chris
Last edited by chrisbt on Mon Oct 17, 2011 10:14 am, edited 1 time in total.
applejack
Power Poster
Power Poster
Posts: 1014
Joined: Fri Mar 30, 2007 2:28 am

Re: How to access Product module output with jquery

Post by applejack »

Just create another CMS page which is hidden from the menu rather that a static HTML page and enter the same Products tag there. With jQuery load you can also load a specific div.
User avatar
chrisbt
Dev Team Member
Dev Team Member
Posts: 203
Joined: Sun Sep 05, 2010 6:11 am

Re: How to access Product module output with jquery

Post by chrisbt »

Thanks for your reply applejack. I'll use jquery to load just the specific div as you suggest. But have realised that I can retrieve the current page and just use jquery to extract the specific div. This eliminates the messiness of having a dummy template & CMS page.
Cheers Chris.
allan1412
Forum Members
Forum Members
Posts: 24
Joined: Wed May 21, 2008 9:14 pm

Re: How to access Product module output with jquery [solved]

Post by allan1412 »

Hi Chris

I was following your post because I'm doing something similar. Can I ask how you are retrieving the current page?

Thanks

Allan
User avatar
chrisbt
Dev Team Member
Dev Team Member
Posts: 203
Joined: Sun Sep 05, 2010 6:11 am

Re: How to access Product module output with jquery [solved]

Post by chrisbt »

Hi Allan, I retrieved the current page using:

Code: Select all

$('#shortlist').load(window.location.pathname + ' #shortlist'); 
with the "+ ' #shortlist' " appended to get jquery to select just the #shortlist element.

However I found this method of loading the whole page was a bit slower so I went back to loading a dummy page that only contains the shortlist content, using:

Code: Select all

$('#shortlist').load('tmp/shortlist.html&showtemplate=false');
This was noticeably faster so I decided to put up with the dummy but inactive CMS page.

Cheers, Chris
allan1412
Forum Members
Forum Members
Posts: 24
Joined: Wed May 21, 2008 9:14 pm

Re: How to access Product module output with jquery [solved]

Post by allan1412 »

Hi Chris

Thanks for this - very helpful and much appreciated.

Allan
Post Reply

Return to “Modules/Add-Ons”