阿贾克斯失败,但状态code仍然是200 QUOT;确定]仍然是、状态、阿贾克斯、code

2023-09-10 17:27:49 作者:作业遍布全球

我不知道为什么会这样,但我有一个简单的Ajax code:

I'm not sure why this is happening but i have a simple Ajax Code:

$.ajax({ url: "/javascript/testing.js"})
    .done(function(data){ console.log(data) })
    .fail(function(jqXHR, textStatus, errorThrown) {
         console.log(jqXHR);
    });

.fail()获取真实执行情况code是OK。另外,数据为present在 responceText 实际合法的数据。为什么会出现这种情况?

.fail() get's executed the status code is "OK". Also the data is present in responceText to the actual legit data. Why is this happening?

推荐答案

如果你想解析JavaScript文件,用的数据类型应该是剧本

If you want to parse the javascript file, then the dataType should be script:

$.ajax({ url: "/javascript/testing.js", dataType: "script" })
.done(function(data){ console.log(data) })
.fail(function(jqXHR, textStatus, errorThrown) {
     console.log(jqXHR);
});

如果你仍然得到一个 parserError 再有就是你的 testing.js 文件有问题。

If you are still getting a parserError then there is a problem with your testing.js file.

如果你不想分析它,只是检索它,用的数据类型应该是文本

If you don't want to parse it and just retrieve it, then the dataType should be text:

$.ajax({ url: "/javascript/testing.js", dataType: "text" })