I’ve just setup a new EmberJS and Rails4 project. I’m using the default DS.RESTAdapter to fetch records from the server. The Accept header it is sending is application/json, text/javascript, */*; q=0.01
. Because of the */*
, the server returns html (see this gist).
I’ve solved this for my application with:
DS.RESTAdapter.reopen({
headers: {
"Accept": "application/json, text/javascript; q=0.01"
}
});
Is this a bug in ember or rails? Should this default be changed?
Looks like this default is from jQuery.ajax(url, {dataType: 'json'})
. What I’m not sure of is what should change. Is this a bug in Rails for returning HTML? Or is it a bug in jQuery for requesting /?
Perhaps either way the Accept header should be set for GET requests, like it is for other requests.
I believe this is a jQuery problem.
As a similar solution, I’m using biceps to version my API. So I need to have a specific accept.
I’ve solved this with:
$.ajaxSetup({
accepts: {
json: 'application/vnd.my_app;ver=1+json'
}
});