The below code has both success and failure handling

jQuery.ajax({

        type:"post",
        dataType:"json",
        url: myAjax.ajaxurl,
        data: {action: 'submit_data', info: info},
        success: function(data) {
            successmessage = 'Data was succesfully captured';
            $("label#successmessage").text(successmessage);
        },
        error: function(data) {
            successmessage = 'Error';
            $("label#successmessage").text(successmessage);
        },
    });

    $(":input").val('');
    return false;

However we are not following the above...We are following as below

jQuery.ajax({

        type:"post",
        dataType:"json",
        url: myAjax.ajaxurl,
        data: {action: 'submit_data', info: info},
        success: function(data) {
            if(data.responseType == 'success') {
                 // success
            }
            if(data.responseType == 'failure') {
                 // failure
            }
        }
    });

    $(":input").val('');
    return false;

Is our approach is the correct or wrong approach ??

Basically every response will be success and show error message based on 
the response type

Please advise. We need to follow the best practice

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to