Displaying widgets in external sites

From JReviews Documentation
Jump to: navigation, search

In order to display widgets in external sites, a request needs to be made from the external site to the host site. This is known as a Cross-origin resource sharing (CORS) request and your server needs to allow this type of requests in order for the widget call to work.

If widgets are not displaying on external sites, you can use Firebug or the Google Chrome Inspector tool to check the console. Typically you will find an error that looks like this:

XMLHttpRequest cannot load http://www.hostdomain.com/index.php?option=com_jreviews&format=ajax&url=widget_…ll&count=5&userrating=1&id=99&task=listings%2Fone&wid=abcd. The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed. Origin 'http://www.externaldomain.com' is therefore not allowed access.

To enable CORS requests to your site you need to edit the .htaccess file and add this line:

Header add Access-Control-Allow-Origin "*"

On Nginx servers without Apache, you need to add something like this to your .conf file:

add_header Access-Control-Allow-Origin *;
proxy_set_header Access-Control-Allow-Origin $http_origin;