jQuery Ajax 404 Handling

前端 未结 6 766
感动是毒
感动是毒 2020-12-03 10:03

Im trying to access a 404 event which I can see coming back as 404 with firebug but the error function is not kicking in, With my below code I always get Error: success ?.

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-03 10:36

    Remove 'url: ' in your code

    Your code :

    $.ajax({
        type: 'get',
        url: 'url: 'https://admin.instantservice.com/resources/smartbutton/5702/10945/available.gif?' + Math.floor(Math.random()*10001),
        success: function(data, textStatus, XMLHttpRequest){
            console.log('Error: ' + textStatus);
        },
        error:function (xhr, ajaxOptions, thrownError){
            alert(xhr.status);
            alert(xhr.statusText);
            alert(xhr.responseText);
        }
    });

    Correct code :

    $.ajax({
        type: 'get',
        url: 'https://admin.instantservice.com/resources/smartbutton/5702/10945/available.gif?' + Math.floor(Math.random()*10001),
        success: function(data, textStatus, XMLHttpRequest){
            console.log('Error: ' + textStatus);
        },
        error:function (xhr, ajaxOptions, thrownError){
            alert(xhr.status);
            alert(xhr.statusText);
            alert(xhr.responseText);
        }
    });

提交回复
热议问题