AJAX没有给我500个请求的responseText?

时间:2018-03-07 15:12:32

标签: javascript ajax

我的ajax上的error附加了一个函数但它不会显示500条响应代码的错误消息吗?我用xhr.responseText显示错误消息,但它返回一个空字符串,有人可以告诉我为什么吗?

$.ajax({
    type: "PUT",
    url: "/ajax/account/create_key",
    data: { key_id: document.getElementById('account-key-value').value, expires_at: document.getElementById('account-key-expires').value },
    success: function(result) {
        // close modal

        swal({
            title: "That was a success!",
            text: 'Your account key has been created.',
            icon: "success",
            button: "Okay!",
        });

        document.getElementById('account-keys-content').innerHTML = result;
    },
    error: function(xhr, ajaxOptions, thrownError) { 
        if(xhr.status == 400) {
            swal({
                title: "Opps!",
                text: xhr.responseText,
                icon: "error",
                button: "Okay!",
            });
        }
        else {
            swal({
                title: "Opps, something went wrong!",
                text: xhr.responseText,
                icon: "error",
                button: "Okay!",
            });
        }
    }       
});

0 个答案:

没有答案