Parker Queen
Parker Queen

Reputation: 619

Codeigniter: AJAX fails to access the controller: Access-Control-Allow-Origin

So I was trying my hands first time on Codeigniter. I tried to build a login system. Have a look here: http://www.henryspike.tk/udemy/

When you try to log in, it is supposed to use AJAX to send data to a controller but the chrome displays an error:

XMLHttpRequest cannot load http://www.henryspike.tk/udemy/index.php/main/login. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://henryspike.tk' is therefore not allowed access. The response had HTTP status code 500.

I searched for the issue and found it has something to do with Cross-Domain stuff. I did not try the remedies since I think that I aint using AJAX from another domain. The controller and the view/jQuery are present on the same domain.

Is it something because I have installed Codeigniter in a sub folder on my domain i.e Udemy! I would like to state that I edited the base url correctly to http://www.henryspike.tk/udemy in my config.php

Upvotes: 1

Views: 2333

Answers (2)

Przemek eS
Przemek eS

Reputation: 1304

Set a header

Maybe have problems with different ports,. It doesn't matter that they are on the same machine/hostname.

Upvotes: 0

charlietfl
charlietfl

Reputation: 171689

www vs no www is considered different subdomain and therefore different origin.

Use a relative url

Upvotes: 1

Related Questions