0

I have a ajax function which will call a function if its error and this error will call a function which displays the error message. here is the code

function Update_uam() {
    $.ajax({
        type: "POST",
        url: "IROA_StoredProcedures.asmx/update_uam1",
        data: "",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function () {
            console.log(tbody);
        },
        error: errorHandler
    });
}

function errorHandler(XMLHttpRequest) {
    console.log(errorHandler.caller.caller);
    console.log(XMLHttpRequest);
}

I tried several ways but seems to failed. What I want to do is also displays which function the error comes from for easy debugging.

Waleed Iqbal
  • 1,308
  • 19
  • 35
Vian Ojeda Garcia
  • 827
  • 4
  • 17
  • 34
  • What I want to do is also displays which function the error comes from for easy debugging? i got this: ƒ (a,c){return e||(c=c||[],c=[a,c.slice?c.slice():c],g.push(c),b||i()),this} – xianshenglu Jan 25 '18 at 07:44
  • Ever heard of a "stack trace"? – Roamer-1888 Jan 25 '18 at 08:02
  • 1
    *"What I want to do is also displays which function the error comes from for easy debugging."* - No. What you want to do is learn how to set breakpoints, use the debugger in the browser's developer tools and how the call stack that it shows you works. – Tomalak Jan 25 '18 at 08:04
  • 1
    https://stackoverflow.com/questions/2648293/how-to-get-the-function-name-from-within-that-function – Krzysztof Raciniewski Jan 25 '18 at 08:23

1 Answers1

1

I think you should use :

function Update_uam() {
    $.ajax({
        type: "POST",
        url: "IROA_StoredProcedures.asmx/update_uam1",
        data: "",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function () {
            console.log(tbody);
        },

        error: function (jqXHR, exception) {
            var msg = '';
            if (jqXHR.status === 0) {
                msg = 'Not connect.\n Verify Network.';
            } else if (jqXHR.status == 404) {
                msg = 'Requested page not found. [404]';
            } else if (jqXHR.status == 500) {
                msg = 'Internal Server Error [500].';
            }
            $('#post').html(msg);
        },
    });
Waleed Iqbal
  • 1,308
  • 19
  • 35
  • Your answer is not wrong, though it does not meet the requested requirements. The user was asking to get the function-name where the error came from. – flx Jan 25 '18 at 08:40
  • This is not wrong but the purpose of the function so the code will be re-usable. – Vian Ojeda Garcia Jan 25 '18 at 09:40