Vivek Malhotra Vivek Malhotra - 1 year ago 76
Ajax Question

406 (Not Acceptable) iron-ajax

This is my code.

<iron-ajax auto

If i manually hit the url in the broswer, it works. But this one does't.
It's a GET request.

Answer Source

HTTP status code 406 means that the server cannot return a representation which conforms to the Accept- headers. From the specs:

The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request.

For more answers see here: What is "406-Not Acceptable Response" in HTTP?

This is most likely the the Accept header set to application/json by the iron-ajax element. The browser (Chrome) on the other hand by default sends requests with

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8

Where the */* bit matches any content type.

To fix you would have to work on the server side to allow JSON responses. You could also try setting the header explicitly although I expect iron-ajax to override Accept header anyway

<iron-ajax headers='{"Accept": "*/*"}' handle-as="json"></iron-ajax>

Again, the */* is just an example. You probably need a more specific media type.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download