- DarkLight
Loading Yotpo Reviews with AJAX
- DarkLight
Yotpo's on-site assets and features load asynchronously. This means that the various widgets will only be loaded once on the initial page load, and will be then ignored by any AJAX scripts running on the page. As such, AJAX-based elements such as endless scroll pages or custom product pages will only appear on the initial page load.
In this article, you'll learn how to load Yotpo Reviews with AJAX.
Loading Yotpo with AJAX
To properly display Yotpo on-site assets on pages that dynamically update content (without reloading the entire page), it is necessary to reinitialize Yotpo assets every time new content is loaded.
To automatically update and re-initiate Yotpo assets, the Javascript below must be added to callback functions when new content is loaded.
For new widgets:
yotpoWidgetsContainer.initWidgets()
For legacy widgets:
yotpo.initWidgets()
In addition to updating the callback functions, be sure to update the relevant widget attributes per product:
For example:
- Product ID
- Product URL
- Product Name
- Product Description
Upon refreshing the page content, on-site assets will be updated to reflect the correct data attributes.