@emiliogambone wrote:
Hi!
I’m trying to send to the server through adapter the record ‘report’. This is my adapter:
import DS from 'ember-data'; import RSVP from 'rsvp'; const { Promise } = RSVP; export default DS.Adapter.extend({ defaultSerializer: 'report', findAll(store){ return new Promise(function(resolve, reject) { let report = store.peekAll('report'); resolve(report); }) }, createRecord(store, type, snapshot){ let data = this.serialize(snapshot, { includeId: true }); return new Promise(function(resolve, reject){ let xhr = new XMLHttpRequest(); var method = 'POST'; var url = 'https://test.vigifarmaco.it/api/v1/submit'; if ("withCredentials" in xhr) { // XHR for Chrome/Firefox/Opera/Safari. xhr.open(method, url, true); } else if (typeof XDomainRequest != "undefined") { // XDomainRequest for IE. xhr = new XDomainRequest(); xhr.open(method, url); } else { // CORS not supported. xhr = null; } if (!xhr) { alert('CORS not supported'); return; } xhr.onreadystatechange = alertContents; xhr.setRequestHeader("Vigifarmaco-Api-Key", "0Utrr0yHwHQbXr9TT1COrQtt"); xhr.setRequestHeader("Content-type" , "text/xml"); xhr.send(data); function alertContents() { if (this.readyState == 4){ if(this.status == 200){ resolve(xhr.responseXML); } else reject(new Error('post: `' + url + '` failed with status: [' + this.status + ']'+ 'failed with readyState:' + this.readyState+' error:' + xhr.responseXML.getElementsByTagName('errors')[0].children[0].firstChild.nodeValue)); } }
this is the controller where i save the record:
import Ember from 'ember'; const { Controller } = Ember; export default Controller.extend({ actions:{ submit(){ this.get('model').reports.save().then(function(value){ alert(value.data.id); alert('segnalazione inviata'); alert(value); this.transitionToRoute('report.lastpage'); //return value; }, function(error){ alert('errore'); console.log(error); }); //get(this, 'model').destroyRecord(); } } });
My problem is that when i try to save the record i get the following message: “Assertion Failed: ‘motorista’ was saved to the server, but the response does not have an id and your record does not either.”
The server response with an XML document.
Any suggestion?
Posts: 2
Participants: 2