@emiliogambone wrote:
route/report/final-check.js`
actions:{ submit(){ var model = this.get('model').reports; var store = this.get('store'); this.get('model').reports.save().then(function(model){ alert('segnalazione inviata'); this.transitionToRoute('report.lastpage'); }, function(error){ console.log(error); });
adapter/reporrt.js
createRecord(store, type, snapshot){ let data = this.serialize(snapshot, { includeId: true }); alert(data); console.log(data); return new Promise(function(resolve, reject){ let xhr = new XMLHttpRequest(); var method = 'POST'; var url = 'https://test.vigifarmaco.it/api/v1/submit'; var headers = { "Vigifarmaco-Api-Key" : "0Utrr0yHwHQbXr9TT1COrQtt", "Content-type" : "text/xml" }; 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); var a = xhr.response; console.log(a); function alertContents() { if (xhr.readyState == 4){ if(xhr.status == 200){ resolve(parseSegnalazione(xhr.responseXML)); } else { reject(new Error('post: `' + url + '` failed with status: [' + this.status + ']'+ 'failed with readyState:' + this.readyState+'')); } } }; function parseSegnalazione(xml){ console.log(xml); var json = { jsonapi: { version: "1.0" }, data: [ ] }; var success = xml.getElementsByTagName('status'); var vigId = xml.getElementsByTagName('vigifarmaco-id'); json.data.push({"id":vigId[0].childNodes[0].nodeValue}); console.log(json); return json; } });
}
Hi everybody!
Here i have this problem: i want to send to the server this data through adapter, but when i try to send it, it seems that in final-check method the callback is always rejected. I can’t understand why! Thank you for response!
Posts: 1
Participants: 1