jQuery.load() error in Safari (OSX) only

Asked

Viewed 158 times

0

I’m having a problem using jquery.load() to load part of another document that only occurs in Safari on Mac (in the latest versions: Safari 7.1 and Osx 10.9.5). All other browsers (including IE) work perfectly.

The error in the Safari console I receive is as follows:

Xmlhttprequest cannot load http://www.dominio.com.br/arquivo_a_ser_carregado.php. Origin http://domain.com.br is not allowed by Acess-Control-Allow-Origin

From what I researched this error happens when there is a request in ajax between two different domains. Although all the files are in the same domain and in the same folder, by the error that is shown, the source domain and what is trying to load the file is with a small difference: one of them is without the WWW and probably that is causing the error.

The code I’m using to load is as follows:

$('.holder').load("arquivo_a_ser_carregado.php #conteudoPort",function(){ 
    console.log('ok'); 
});

As I said earlier, this error is only occurring in Safari on Mac. Even by placing the absolute url I keep getting the same error.

If anyone’s been through this and has some light to help me, I’d really appreciate it. Thank you very much.

1 answer

1

If you have control of the server that responds to the ajax request, try to configure the header Response with:

Access-Control-Allow-Origin: *

Even small variations such as www can influence how the browser identifies the domain.

As you are using php, you can also try using php:

<?php header('Access-Control-Allow-Origin: *'); ?>

Attention to the *. Replace it as needed, otherwise your domain will accept requests for any other domain.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.