question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Content-type and Encoding

See original GitHub issue

Hi there,

I’m trying to send a custom ajax call to my backend server, which is a JSONAPI.org server. I don’t know why, but when I try to send a Content-Type header (application/vnd.api+json) ember-ajax is form encoding the request.


      this.get('ajax').request('/api/v1/things', {
        method: 'POST',
        data: {
          // ......
        },
        headers: {
          'Content-Type': 'application/vnd.api+json',
          'Accept': 'application/vnd.api+json'
        }
      }).then( jsonapiResponse => {
         // .....
      });

Checking my server logs is getting the body sent as a big form encoded blob, rather than JSON.

Am I doing something wrong?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tarascommented, Jan 31, 2016

@brandonparsons Content-Type should be specified as they’re in jQuery by providing contentType key to options hash.

this.get('ajax').request('/foo', { contentType: 'application/vnd.api+json' })

For all other headers, you can use headers hash as you have been.

1reaction
brandonparsonscommented, Jan 30, 2016

Hi @alexlafroscia - I did extend it, but only barely:

import Ember from 'ember';
import AjaxService from 'ember-ajax/services/ajax';


export default AjaxService.extend({

  session: Ember.inject.service(),

  headers: Ember.computed('session.data.authenticated.token', {
    get() {
      let headers = {};
      const authToken = this.get('session.data.authenticated.token');
      if (authToken) {
        headers['Authorization'] = `Bearer ${authToken}`;
      }
      return headers;
    }
  })

});
Read more comments on GitHub >

github_iconTop Results From Across the Web

What does "Content-type: application/json; charset=utf-8 ...
Content-type : application/json; charset=utf-8 designates the content to be in JSON format, encoded in the UTF-8 character encoding. Designating the encoding ...
Read more >
Content-Type - HTTP - MDN Web Docs - Mozilla
The Content-Type representation header is used to indicate the original media type of the resource (prior to any content encoding applied ...
Read more >
Setting the HTTP charset parameter - W3C
Hints on sending out character encoding information using the HTTP charset parameter. Includes pointers on how to set up your server or send ......
Read more >
What's the basic difference between Content-Type ... - Quora
Content-type : is format of data sending or accepting from source to destination and vice versa. Content-Encoding : is the text sent through...
Read more >
Content Encoding: why and how to use the meta charset tag ...
Content Encoding: why and how to use the meta charset tag and the Content-Type header ... Improving the speed at which a web...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found