Solicitud jQuery .ajax PUT que no respeta el encabezado personalizado

I'm losing my custom header when using PUT type with .ajax. But, the header is fine with GET, but gets mangled with PUT. Please see evidence 1:

// GOOD GET:

$.ajax({
    url: url,
    type: 'GET',
    dataType: 'json',
    headers: {
        Accept: "application/json"
    }
});

// Actual header sent (using fiddler):
Accept: application/json

// BAD PUT:

$.ajax({
    url: url,
    type: 'PUT',
    dataType: 'json',
    headers: {
        Accept: "application/json"
    }
});

// Actual header sent (using fiddler):
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

As you can see the only difference is the value of type causing the value of the Accept part of the header gets trashed. jquery-1.8.2.js. Any thoughts? Thanks

Apuñalar

preguntado el 04 de diciembre de 12 a las 04:12

From jQuery API docs: The type of request to make ("POST" or "GET"), default is "GET". Note: Other HTTP request methods, such as PUT and DELETE, can also be used here, but they are not supported by all browsers. -

I saw that in their documentation, but I expected either webkit or FF to work with PUTs and they don't. This leads me to believe its a problem with jquery. Doesn't .ajax set the headers. I will test with plain xhr requests today -

I would "expect" those browser to work too, but what do we really know? At the same time, there could be a good chance it's jQuery :) -

1 Respuestas

It seems it is browser related:

http://jsfiddle.net/oceog/WqXzA/

Request URL:http://fiddle.jshell.net/_display/
Request Method:PUT
Status Code:200 OK
Request Headersview source
Accept:application/json

Chrome 25.0

Respondido el 04 de diciembre de 12 a las 04:12

I do in fact get different Accept headers in firefox and chrome. Chrome gives me /. Does this mean that I basically have no control over the accept header when using a PUT? THats a hard pill to swallow - atigrado laredo

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.