O jQuery AJAX falha ao funcionar (solicitação de pré-vôo OPTIONS) quando os cabeçalhos são especificados
A solicitação AJAX funciona bem, mas no momento em que adiciono um cabeçalho via beforeSend ou headers, uma solicitação de pré-vôo OPTIONS é feita e a solicitação GET é abortada.
Code: $.ajax({
type: "GET",
crossDomain: true,
beforeSend: function (xhr)
{
xhr.setRequestHeader("session", $auth);
},
url: $url,
success: function (data) {
$('#something').html(data);
},
error: function (request, error) {
$('#something').html("<p>Error getting values</p>");
}
});
Semelhante Solicitação AJAX sem cabeçalhos especificados (no momento em que adiciono / modifico o cabeçalho, é feita uma chamada OPTIONS)
Request GET /api/something?filter=1 HTTP/1.1
Referer http://app.xyz.dj/dashboard
Accept application/json, text/javascript, */*; q=0.01
Accept-Language en-US
Origin http://app.xyz.dj
Accept-Encoding gzip, deflate
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; MASMJS; rv:11.0) like Gecko
Host 162.243.13.172:8080
DNT 1
Connection Keep-Alive
Cache-Control no-cache
Cabeçalho de resposta do servidor semelhante (para solicitação GET)
Response HTTP/1.1 200 OK
Server Apache-Coyote/1.1
Access-Control-Allow-Origin *
Access-Control-Allow-Methods GET, POST, DELETE, PUT, OPTIONS, HEAD
Access-Control-Allow-Headers Content-Type, Accept, X-Requested-With
Access-Control-Allow-Credentials true
Content-Type application/json
Transfer-Encoding chunked
Date Thu, 09 Jan 2014 14:43:07 GMT
O que estou fazendo errado?