The thing that I had to do is setup my apache server
- Activate the module
a2enmod headers
service apache2 restart
2 . And edit the file /etc/apache2/sites-enabled
<VirtualHost *:80>
....
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
...
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
...
#The things that I added
Header set Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, content-type"
Header always set Access-Control-Allow-Methods "POST, GET, PUT, DELETE, OPTIONS"
#End of the thigns that I added
</VirtualHost>
EDIT
The above answer only works on localhost, but when I tryed to do it on hosting or whaterver cloud, The mistake persevere, so the answer was the magic bundle
The installation :
php composer.phar require nelmio/cors-bundle:~1.0
Then add to project/app/AppKernel.php
public function registerBundles()
{
$bundles = array(
...
new Nelmio\CorsBundle\NelmioCorsBundle(),
...
);
...
}
Now the setup of the bundle and my paths on project/app/config/config.yml
add
nelmio_cors:
defaults:
allow_credentials: true
allow_origin: []
allow_headers: []
allow_methods: []
expose_headers: []
max_age: 0
hosts: []
paths:
'^/':
allow_origin: ['*']
allow_headers: ['origin', 'content-type']
allow_methods: ['POST', 'PUT', 'GET', 'DELETE','OPTIONS']
max_age: 3600
To summary it's works!!