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?
- 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
1 Answer
Reset to default 8PowerReviews 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
版权声明:本文标题:javascript - Getting PowerReviews to load properly with AJAX - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744225068a2596048.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论