Ok, i got it. This is only for “hard errors” and NOTto handle logical business logic responses(like: Transaction failed (balance low)) from server side.
Yep, if you are not using response code, to mark an error, you will need to check data in the success response.
By using the promise syntax it will look like
var data = webix.ajax().post(url, data).then(function(data){
//return { "error":"something"} to trigger an error
var is_error = data.json().error;
if (is_error) throw(is_error);
});
@maksim for a successful response , should’nt the example be like this?
var data = webix.ajax().post(url, data).then(function(data){
//return { "error":"something"} to trigger an error
var is_error = data.json().error;
if (is_error) throw(is_error);
else return data; // return data to trigger success_callback
});
data.then(success_callback, error_callback);
Can you plesae put an example how can I get fields from data in success response? I am trying data.json().fieldname, but it is always undefined. Thanks
Hey @ftedin, please take a look at the following example: https://snippet.webix.com/ekthk202. I’m not sure what the issue in your case might be, but you are either not getting a response object, or you are referring to the wrong property name.
The sample you sent is a get, I am talking about post request. I am able to get the json back and I see the correct values in the console, but I am not able to get the value of each field in the json, I just see them when I print it out in console using data,json(), but I am not able to reference any field on it. Thanks.
The principle stays exactly the same, be it a GET or a POST request - https://snippet.webix.com/0lws9r0y. I am not quite sure what the issue might be in your case, but it is probably related to your server specifically.