0

I have installed codeigniter application in a subfolder, whenever i send ajax request i get this error:

No 'Access-Control-Allow-Origin' header is present on the requested resource.

My .htaccess is:

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]

My config.php is:

$config['base_url'] = 'http://jmwglobal.com/locker/';

I don't know why i am getting this error. I have tried almost all remedies available on internet/stackoverflow but no solution found.

Waqar
  • 826
  • 5
  • 16

1 Answers1

0

I find the solution, It was deeply written in somewhere in STACKOVERFLOW.

Thanks to this post. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '...' is therefore not allowed access

JavaScript code is limited by the same-origin policy, meaning, from a page at www.example.com, you can only make (AJAX) requests to services located at exactly the same domain, in that case, exactly www.example.com (not example.com - without the www - or whatever.example.com).

What I did is i just put these two lines in my htaccess,

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]

These line actually remove www from URL. This is important because as @acdcjunior Said in the above post that www.domain.com is different from domain.com for javascript.

BIG THANKS TO @acdcjunior.

Community
  • 1
  • 1
Waqar
  • 826
  • 5
  • 16