0

For example if I have the JS ajax get/post function

function cancelFeeReport() {
        var postData = "claimId=" + $("#FeeReport_ClaimID").val() + "&page=@ViewBag.PageNumber";
        $.ajax({
            type: "POST",
            url: '@Url.Action("Cancel", "FeeReports")',
            dataType: "json",
            async: false,
            data: postData,
            success: function (result) {
                // Do something
            },
            complete: function () {
                // Do nothing for now.
            }
        });
    }

When an error happened in the above JS function. How to identify that cancelFeeReport() threw the error to AJAX global error handler

$(document).ajaxError(function( event, jqxhr, settings, thrownError ) {
       alert('Error in ' + <functioname>);
});
Vijai
  • 2,369
  • 3
  • 25
  • 32
  • 2
    This is not a trivial thing to do in JS. Check out the second answer in [this question](http://stackoverflow.com/questions/280389/how-do-you-find-out-the-caller-function-in-javascript) for more info. The first won't apply here, as the call stack will go through multiple levels of anonymous functions. – Rory McCrossan Jul 19 '16 at 20:15
  • Ajax errors are not *thrown*, so there's no way to get a stack trace for it. – Bergi Jul 19 '16 at 23:22
  • So if I want to behave differently for a particular AJAX call error, I can't use global error handler? – Vijai Jul 20 '16 at 17:00

0 Answers0