Hello,
in the following code i send a json with a firstname, lastname and phone number and get a 200 Status Code back.
Thats good but i came never to the part ‘Do something with the result’.
Instead i came in the part ‘An error occurred somewhere in the Promise chain’ and get a Fuse.Scripting.V8.Object Error in the Monitor.
I tested the same json with an RESTeasy extension for Chrome an here i get a response back ‘{“notice”: {“text”: “Customer Added”}’.
Can help me anyone?
Thanks and sorry for my bad english
var Observable = require("FuseJS/Observable");
var username = Observable("");
var password = Observable("");
var email = Observable("");
var data = Observable();
function click() {
var requestObject = {first_name: username.value, last_name: email.value, phone: password.value};
var status = 0;
var response_ok = false;
fetch('http://slimapp.dev/api/customer/add', {
method: 'POST',
headers: { "Content-type": "application/json", "Accept": "application/json" },
body: JSON.stringify(requestObject)
}).then(function(response) {
status = response.status; // Get the HTTP status code
response_ok = response.ok; // Is response.status in the 200-range?
console.log("Status Code " + status);
return response.json(); // This returns a promise
}).then(function(responseObject) {
// Do something with the result
console.log('do something');
data.value = responseObject;
}).catch(function(error) {
// An error occurred somewhere in the Promise chain
console.log('error ' . error);
debugger;
});
}
module.exports = {
username: username,
email: email,
password: password,
click: click,
data: data,
};