JQueryAJAX调用:304 respose产生一个错误

JQuery AJAX call: 304 respose produces an error

本文关键字:一个 错误 调用 respose JQueryAJAX      更新时间:2024-04-26

我在localhost上有一个脚本,它向同一域发送GET请求。它导致304响应,JQuery显然将其视为错误。

$(document).ready(function(){
    $.ajax({
        type: 'GET',
        url: 'http://localhost/file.js',
        error: function(e) {
            console.log('error: ' + e.responseText); // I see this message in console
        },
        success: function(e) {
            console.log('success: ' + e.responseText); // I don't see this message in console
        }
    });
});

1) 为什么我会得到304的回复?2) 如何修改代码以便调用success函数?(而不是错误函数)

我猜错误源于您收到一个.js文件,jQuery需要json

如果您正在加载一个js文件,请将dataType:"script"添加到您的ajax中,以强制它使用js