webix.ajax().post error and success

edited April 2016 in Technical questions

I have the function below.
What does the server side code need to return so that
the correct (error or success) is executed?

webix.ajax().post("URL", variableJSON, {
                    error:function(text, data, XmlHttpRequest){
                        alert("error");
                    },
                    success:function(text, data, XmlHttpRequest){
                        alert("success");
                    }
                });
Tagged:

Comments

  • Error callback will be executed if the status code of an HTTP request will be 0 or >=400.

  • 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.

  • to handle logical business logic responses

    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);
    });
    

    data.then(success_callback, error_callback);

  • @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);
    
  • Yep, sure, I have shown an error handling, but forgot to write the last return line

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!