为什么我的 $.ajax 没有出现在“网络”选项卡中,但在新选项卡中打开却有效?

Why is my $.ajax not showing up in Network tab, but opening in a new tab works?

这是我的 AJAX 代码:

jQuery.ajax({url: url,
    method: 'GET',
    data: getParams,
    /*success: function (json, textStatus, jqXHR) {
        if(jQuery.active <= 1){
            waitDialog.removeWaitDialog();
        }

        createProcessButtonEvent();

        ajaxError = false;
        returnFunction(jqXHR.responseJSON);
    },*/
    complete: function(jqXHR, textStatus, errorThrown) {
        if(jQuery.active <= 1){
            waitDialog.removeWaitDialog();
        }

        createProcessButtonEvent();

        var response;
        if (typeof jqXHR.responseJSON === 'object') {
            response = jqXHR.responseJSON;
        } else {
            response = jqXHR.responseText;
        }

        if(response.errors.length == 1){ // jsonResults.message != ''
            if(!warningMessage){ //hard coded for ad designer
                jQuery('#alertMessageText').text(response.errors[0].message);
                jQuery('#alertMessage').show();
                jQuery('#waitDialog').jqmHide();
                ajaxError = true;
                return;
            }
            warningMessage.displayMessage(response.errors[0].message);
            jQuery('.popup').modal('hide');
            jQuery('.popup').not('.persist').remove();
        }
        if (response.errors.length > 1){
            for(var n = 0; n < response.errors.length; n++){
                if (response.errors[n].id == 1){ // 2005
                    window.location.href = '/login?destination=' + encodeURIComponent(window.location.pathname + window.location.search);
                }
                if (response.errors[n].id == 9500){
                    statusMessage.displayMessage(response.errors[n].message);
                }
            }
            ajaxError = true;
            //if(errorFunction){
            //  errorFunction(jsonResults);
            //}
            waitDialog.removeWaitDialog();
        }

        if (!ajaxError) {
            returnFunction(jqXHR.responseJSON);
        }
    },
    dataType: 'json',
    contentType: 'application/json'
});

我告诉它转到 http://127.0.0.1/api/parameter,其中 parameter 是无效资源。我的 API returns 在新标签页中:

{"errors":[{"id":3,"message":"GET route not defined for /api/parameter"}],data:{}}

我让它返回 500 状态代码,因为访问无效资源是一个错误。当我调用实际的 AJAX 时,我得到 jqXHR.responseJSONnull,而 jqXHR.responseText''

我已经尝试使用 success:error: 块,并尝试了 complete: 因为我的 API 似乎在错误块出现后解决了调用已被调用,正如您在评论中看到的那样。

所以我得到 TypeError: response is null,因为我的响应对象从未被填充,最奇怪的是我对 parameter?parameters=here 的调用永远无法在网络

中进行检查

由于我控制了 API,我将此特定错误更改为 return,状态代码为 501 Not Implemented,而不是 500,它似乎有效。看起来这是一个非常独特的边缘案例。