JoeM05
JoeM05

Reputation: 922

XMLHttpRequest status 0

I'm using jquery ajax call and Chrome javascript console is spitting out an error:

XMLHttpRequest cannot load http://www.1luckypixel.com/eppy/fong_app/index.php/fb_login/login_user. Origin http://1luckypixel.com is not allowed by Access-Control-Allow-Origin.

I've done some searching and find a lot of info for "Origin NULL is not allowed by Access-Control-Allow-Origin." But this is actually giving my domain name as the un allowed origin. I'm not sure what the error means. Also the request goes to the server but doesn't come back and the data in the request isn't past.

Here is my code in case that helps:

$.ajax({
        type : 'POST',
        url : "<?= base_url(); ?>index.php/fb_login/login_user",
        data: {
            name:response.name , img:response.link+'/picture' , fb_id:response.id
        },
        beforeSend : function(thing,data) {
            console.log('before', data);
        },
        error : function(XMLHttpRequest, textStatus, errorThrown) {
            console.log('xmlhttprequest', XMLHttpRequest);
            console.log('textStatus', textStatus);
            console.log('errorthrown', errorThrown);
        }
    }); 

Upvotes: 1

Views: 2817

Answers (1)

Quentin
Quentin

Reputation: 943568

www.1luckypixel.com is not the same as 1luckypixel.com

Use a relative URL in your JavaScript, not an absolute one.

Better yet, pick one of the two hostnames to be canonical and redirect all the traffic from the other one to it (with an HTTP 301 status code).

Upvotes: 4

Related Questions