Cross-Origin Resource Sharing

Web hosting discussion, programming, and shared and dedicated servers.
2 posts Page 1 of 1
by gpelpel » Tue May 09, 2017 11:04 pm
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
by drew.phillips » Thu May 11, 2017 3:53 pm
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!
Drew Phillips
Programmer / System Operations, Sonic.net
2 posts Page 1 of 1

Who is online

In total there are 2 users online :: 0 registered, 0 hidden and 2 guests (based on users active over the past 5 minutes)
Most users ever online was 422 on Sat May 26, 2012 5:28 am

Users browsing this forum: No registered users and 2 guests