Q:

XMLHttpRequest cannot load url. Method PUT is not allowed by Access-Control-Allow-Methods in preflight response

I am using angularjs $http for ajax request. It is working fine with get and post but giving error in case of put.
Response Header :
Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept, Accept-Encoding, Accept-Language, Host, Referer, User-Agent, X-API-KEY
Access-Control-Allow-Methods:OPTIONS
Access-Control-Allow-Origin:*
Access-Control-Max-Age:1728000
Content-Length:0
Date:Mon, 25 Jan 2016 08:44:05 GMT
Server:spray-can/1.3.2

Request Header : 
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8,hi;q=0.6
Access-Control-Request-Headers:accept, content-type, x-api-key
Access-Control-Request-Method:PUT
Connection:keep-alive
Host:localhost:8080
Origin:http://localhost:8000
Referer:http://localhost:8000/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36

A:

Try to setup following headers:
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Origin, Content-Type, Authorization, X-Auth-Token');
header('Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS');

