November 25, 2015

jquery ajax error handling

$.ajax({
    url: 'http://10.2.3.4/api/user',
    type: 'GET',
    dataType: 'json',
    success: function() { alert("Success"); },
    error: function(jqXHR, textStatus, errorThrown) {
        alert('An error occurred');
        $('#result').html('<p>status code: '+jqXHR.status+'</p><p>errorThrown: ' + errorThrown + '</p><p>jqXHR.responseText:</p><div>'+jqXHR.responseText + '</div>');
        console.log('jqXHR:');
        console.log(jqXHR);
        console.log('textStatus:');
        console.log(textStatus);
        console.log('errorThrown:');
        console.log(errorThrown);
    },
});

No comments:

Post a Comment