Page 1 of 1

Cross-Origin Resource Sharing

Posted: Tue May 09, 2017 11:04 pm
by gpelpel
Does Sonic.net support cross-origin resource sharing?
I have some javascript codes that call an external server via Ajax commands. They work great on all other systems but not on Sonic. Is there a setting to activate?
Thanks

Re: Cross-Origin Resource Sharing

Posted: Thu May 11, 2017 3:53 pm
by drew.phillips
Can you elaborate on the specifics of what domain you're trying to perform an Ajax request to?

If you're site is hosted on Sonic and you're trying to make an Ajax request to a remote domain, then Sonic doesn't need to support anything; it's up to the browser and the remote site to permit/deny the request.

If you're trying to make an Ajax request to a Sonic hosted site, then you'll need to configure that site/URI to send the appropriate headers to permit it from the calling domain.

Since you can only specify one domain per request, it often takes some kind of code or special .htaccess rules to apply the CORS headers correctly.

For example, in PHP:

Code: Select all

$http_origin = @$_SERVER['HTTP_ORIGIN'];
if (
    preg_match('/domain1\.com$', $http_origin) ||
    preg_match('/domain2\.com$/', $http_origin) ||
    preg_match('/third-domain\.net$/', $http_origin)
) {
    header('Access-Control-Allow-Origin: ' . $http_origin);
}
Basically, we fully support it.

StackOverflow.com is a good place to get help with programming issues like this as well.

Good luck!