admin管理员组

文章数量:1399950

We are using PowerReviews within our Magento store as an over-ride to the standard Magento review system. We have it set up for the Category, Product, and Review pages and has been working fine for some time now.

Recently I added a module which brings AJAX reload functionality to the filtered navigation on the category page. i.e. I choose "Red" as a filter and the category page refreshes without reload with the proper products. This works fine when I have Power Reviews turned off.

When Power Reviews is on, the AJAX begins to load but then the page goes white and only the PowerReviews <div> tags are shown. When I look at the PowerReviews code I think I can see the reason:

<script type="text/javascript">
  POWERREVIEWS.display.snippet(document, {
       pr_page_id : '49DAF4', 
       pr_write_review :    '/review/product/list/id/1907/category/111/#review-form',
       pr_read_review : txt, pr_snippet_min_reviews : 1});
</script>

Since the POWERREVIEWS.display.snippet is being called to 'document' what I think is happening is the AJAX load is happening, getting written to 'document' then the PowerReviews is happening and is also getting written to 'document'. Since this happens last, it hijacks the page instead of getting placed properly like it does on a normal load.

If I change 'document' to something like document.getelementbyid('PWR') and add a <div id="PWR"> the snippet will not show on page. Is there a way I can target the output of POWERREVIEWS.display.snippet to something other than 'document' so the two scripts don't interfere with each other?

We are using PowerReviews within our Magento store as an over-ride to the standard Magento review system. We have it set up for the Category, Product, and Review pages and has been working fine for some time now.

Recently I added a module which brings AJAX reload functionality to the filtered navigation on the category page. i.e. I choose "Red" as a filter and the category page refreshes without reload with the proper products. This works fine when I have Power Reviews turned off.

When Power Reviews is on, the AJAX begins to load but then the page goes white and only the PowerReviews <div> tags are shown. When I look at the PowerReviews code I think I can see the reason:

<script type="text/javascript">
  POWERREVIEWS.display.snippet(document, {
       pr_page_id : '49DAF4', 
       pr_write_review :    '/review/product/list/id/1907/category/111/#review-form',
       pr_read_review : txt, pr_snippet_min_reviews : 1});
</script>

Since the POWERREVIEWS.display.snippet is being called to 'document' what I think is happening is the AJAX load is happening, getting written to 'document' then the PowerReviews is happening and is also getting written to 'document'. Since this happens last, it hijacks the page instead of getting placed properly like it does on a normal load.

If I change 'document' to something like document.getelementbyid('PWR') and add a <div id="PWR"> the snippet will not show on page. Is there a way I can target the output of POWERREVIEWS.display.snippet to something other than 'document' so the two scripts don't interfere with each other?

Share Improve this question edited Aug 8, 2012 at 19:23 kmatyaszek 19.3k9 gold badges61 silver badges66 bronze badges asked Aug 8, 2012 at 19:12 Greg DemetrickGreg Demetrick 7591 gold badge12 silver badges28 bronze badges 3
  • 1 Might be useful to have a link to your site to get a better feel for what's going on here. You've got reviews on your category pages or the JS isn't even rendering any reviews, but still conflicting on these pages? Might also help to be able to inspect and play with the html/js. – kalenjordan Commented Aug 8, 2012 at 23:22
  • Alas, I can not provide a link to the issue/error as it will massively break our live website and our development site is protected. To see how PWR is implemented without the AJAX you could look at americanmeadows./flower-bulbs/tulip-flower-bulbs . WHat we have on our category pages are the PWR Snippet which is delivered in a similar way was the reviews. On first load the snippets show up fine. On AJAX reload, the page will only show PWR content.I will see if I can set a test up somewhere. – Greg Demetrick Commented Aug 9, 2012 at 13:01
  • From where I can get the API to fetch review details for products, Is it possible? – Dipak Commented Aug 1, 2014 at 6:47
Add a ment  | 

1 Answer 1

Reset to default 8

PowerReviews actually provided an answer to this which works. They suggested using a JQuery delivery method to the DIV directly. Posting it here to help others.

1) Insert a JS include to a jquery library within the section (if you don't already):

<script src="http://ajax.googleapis./ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>

2) Use the write : function(content) syntax for the snippet function call:

<div id="pr_snippet_category_12345"> <script type="text/javascript">
POWERREVIEWS.display.snippet({ write : function(content) {
$('div#pr_snippet_category_12345').append(content); } }, { pr_page_id
: '12345', pr_snippet_min_reviews : '1' }) </script> </div>

本文标签: javascriptGetting PowerReviews to load properly with AJAXStack Overflow