Quite a useful method when you want to check for errors in Ajax.

Medium 8432968631

Good evening, this is Bono.

I was having a hard time using Ajax, because it just wouldn't SUCCESS, and was turning into an ERROR.

I leave this as a reminder of useful methods in such cases.

make it throw an error code

First, place the code below anywhere you like on the page.

<div id ="XMLHttpRequest"></div>
<div id="textStatus"></div>
<div id ="errorThrown"></div>  

All that remains is to write the following in the code in $.ajax in JavaScript.

    data: hoge,
    dataType: "json",
    type: "post",
    url: "hoge/foo",
    success: function(event){XXX}
    error: function(XMLHttpRequest, textStatus, errorThrown) {
        $("#XMLHttpRequest").html("XMLHttpRequest: " + XMLHttpRequest.status);
        $("#textStatus").html("textStatus: " + textStatus);
        $("#errorThrown").html("errorThrown: " + errorThrown.message);