www.webdeveloper.com
Results 1 to 4 of 4

Thread: XMLHttpRequest cannot load… Origin null is not allowed by Access-Control-Allow-Origin

  1. #1
    Join Date
    May 2013
    Location
    Pouso Algre , Minas Gerais, Brazil
    Posts
    2

    XMLHttpRequest cannot load… Origin null is not allowed by Access-Control-Allow-Origin

    I am trying to print a json that this broker on my server, but i can not return the json, the chorme me of the following error:

    XMLHttpRequest can not load .... Origin null is not allowed by Access-Control-Allow-Origin.

    can someone help me?

    the following code:`

    Code:
    console.log("carregando..");
    var username = "admin";
    var password = "password";
    $.ajax({
    
       type: 'GET',
        url: 'http://localhots/api/json/broker/dest-metrics',
        dataType: 'json',
        headers : {Accept : "application/json","Access-Control-Allow-Origin" : "*"},
        beforeSend : function(req) {
                                        req.setRequestHeader('Authorization', "Basic " +Base64.encode(username+":"+password))
                                        console.log("Autenticado!!");
        },
        success: function(data) { console.log("Sucesso!!"); },
        error: function (data) {
                  console.log("ERRO");
             },
        data: {},
       async: false,
       cache: false,
       jsonp: true 
    
    
    
    });`

  2. #2
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    take out your custom headers, you don't need them and they are breaking the CORS.

  3. #3
    Join Date
    May 2013
    Location
    Pouso Algre , Minas Gerais, Brazil
    Posts
    2
    I configured my virtual machine on the server apache the CORS with this line of code:

    <VirtualHost *:80>
    DocumentRoot "/path/to/website/root"
    ServerName domain.tld
    Header set Access-Control-Allow-Origin http://example.com
    Header set Access-Control-Allow-Methods POST,GET
    Header set Access-Control-Allow-Headers X-Authorization,X-Requested-With
    </VirtualHost>


    and still giving error!

  4. #4
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    the jquery headers are what i was talking about, not the server.
    since you don't whitelist the custom request headers "Accept" or "Access-Control-Allow-Origin" headers, the CORS request cannot be completed.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles