Answer the question
In order to leave comments, you need to log in
Why does Ember send data incorrectly when making a PUT request?
Such a disaster. I am sending a PUT request for an update. On the back for the test, I simply return the title. Through postman it works if you set the content type to application/x-www-form-urlencoded. I also installed it in the adapter, but the title returns in the postman, but not in the ember. Where could be the problem?
import RESTAdapter from 'ember-data/adapters/rest';
import config from '../config/environment';
import Inflector from 'ember-inflector';
import _ from 'lodash';
const { API_HOST, API_PREFIX } = config,
inflector = Inflector.inflector,
dataType = 'json',
contentType = 'application/json; charset=utf-8';
export default RESTAdapter.extend({
host: API_HOST,
namespace: API_PREFIX,
defaultSerializer: 'JSONSerializer',
headers: {},
sendRequest(body) {
return new Ember.RSVP.Promise((resolve, reject) => {
Ember.$.ajax(body).then(
data => Ember.run(null, resolve, data),
jqXHR => {
jqXHR.then = null; // tame jQuery's ill mannered promises
Ember.run(null, reject, jqXHR);
}
);
});
},
updateRecord(store, type, snapshot) {
const pathname = inflector.pluralize(_.camelCase(type.modelName)),
{ id } = snapshot;
let data = this.serialize(snapshot, { includeId: true }),
namespace = this.get('namespace'),
host = this.get('host'),
sendRequest = this.get('sendRequest'),
headers = this.get('headers'),
dataType = 'text',
contentType = 'application/x-www-form-urlencoded',
url = `${host}/${namespace}/${pathname}/${id}`;
let sendData = JSON.stringify(data);
return sendRequest({ type: 'PUT', headers, url, dataType, contentType, sendData });
},
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question