gpt4 book ai didi

jQuery - AJAX statusCode 方法未被调用

转载 作者:行者123 更新时间:2023-12-01 04:13:20 25 4
gpt4 key购买 nike

我已经阅读了几十篇关于如何正确处理来自 jQuery AJAX 调用的 HTTP 状态代码的文章,但我完全失败了。也许有一个错误?如果这个问题在其他地方得到了回答,请原谅我,但我根本无法让它发挥作用。

我正在尝试使用 Musicbrainz 版本 UUID 从封面艺术文件库加载专辑插图。如果没有艺术,他们的服务器将返回 404,如果直接返回 JSON,则返回 200,或者更常见的是,如果重定向到 JSON(带有最终图像信息),则返回 307。

我使用 PHP/CURL 在服务器端进行此工作,但它会导致页面加载长时间延迟(因为服务器会阻止等待 coverartarchive.org 的响应)。我想让客户端异步加载专辑插图。

这是我所拥有的 - 请注意,仅调用错误回调;没有调用任何 statusCode 函数。我已经尝试了很多不同的版本。没有工作。我读到浏览器拦截了 307 重定向,但甚至没有触发 404 回调。

 $('.album_art').each(function() {
var me = $(this);
var uuid = me.data("uuid");
var artistName = me.data("artist");
var trackName = me.data("track");

console.debug("Loading cover art for track "+uuid+ " artist name and track name: " + artistName, trackName);

$.ajax({
type: 'GET',
cache: 'FALSE',
//contentType: "application/json",
url: "http://coverartarchive.org/release/"+uuid,
//data: jsonString,
statusCode: {
200: function () {
console.debug("200 for " + uuid);
},
307: function () {
console.debug("307 for " + uuid);
},
404: function () {
console.debug("404 for " + uuid);
}
}
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.debug("error for " + uuid);
}
});
}); // sorry, indentation is a bit out after copy/paste

Firebug 控制台输出的一些示例专辑/版本的片段:

Loading cover art for track 695ca8ba-16f3-4231-bf03-6ba81d435b72 artist name and track name: Nirvana Smells Like Teen Spirit
GET http://coverartarchive.org/release/695ca8ba-16f3-4231-bf03-6ba81d435b72
307 TEMPORARY REDIRECT 239ms

Loading cover art for track 49364063-bcb6-4d9f-b2bc-940f76495db9 artist name and track name: INXS Kiss the Dirt (Falling Down the Mountain)
GET http://coverartarchive.org/release/49364063-bcb6-4d9f-b2bc-940f76495db9
404 NOT FOUND 249ms

Loading cover art for track b09e7fcf-0383-4e7c-acb0-d5ab437d6713 artist name and track name: Midnight Oil Blot
GET http://coverartarchive.org/release/b09e7fcf-0383-4e7c-acb0-d5ab437d6713
404 NOT FOUND 285ms

Loading cover art for track 90ab8c15-08c8-424e-9d18-62f2f35dae7a artist name and track name: Macklemore & Ryan Lewis feat. Wanz Thrift Shop
GET http://coverartarchive.org/release/90ab8c15-08c8-424e-9d18-62f2f35dae7a
307 TEMPORARY REDIRECT 285ms

Loading cover art for track 433ffa89-1e6a-434a-9bfe-6690f3b6e32a artist name and track name: Them Crooked Vultures Mind Chaser, No Eraser
GET http://coverartarchive.org/release/433ffa89-1e6a-434a-9bfe-6690f3b6e32a
404 NOT FOUND 286ms

Loading cover art for track bc091f8f-17cc-4ad3-8ca3-a7d080c61e1d artist name and track name: Nine Inch Nails The Good Soldier
GET http://coverartarchive.org/release/bc091f8f-17cc-4ad3-8ca3-a7d080c61e1d
404 NOT FOUND 296ms
error for 7b382603-3fda-47d0-8b86-8c661ad616ca
error for 909fbadc-46a5-4bd6-864b-e36d9b47a98e
error for 39ec579c-7a31-4edd-9fd5-d1f48731bf92
GET http://archive.org/download/mbid-dfeacac3-16f0-4ef7-94de-e25679b050c2/index.json
302 Moved Temporarily 1.39s
error for 49364063-bcb6-4d9f-b2bc-940f76495db9
error for b09e7fcf-0383-4e7c-acb0-d5ab437d6713
error for 433ffa89-1e6a-434a-9bfe-6690f3b6e32a
GET http://archive.org/download/mbid-b776a4df-e8a4-4f23-838a-600b5db75ad3/index.json
302 Moved Temporarily 1.45s
GET http://archive.org/download/mbid-69acc6e3-7fe6-4c8c-991e-860677dcf0db/index.json
302 Moved Temporarily 1.63s
error for bc091f8f-17cc-4ad3-8ca3-a7d080c61e1d
error for 4b5657bb-6209-493a-9e64-2bae4c3d4f1a

特别是,这看起来像是完全相同的问题: jquery ajax statusCode: 502 function never called

最佳答案

我用下面的代码来显示 statusCode 是 0:http://jsfiddle.net/brGTj/

uuid = "90ab8c15-08c8-424e-9d18-62f2f35dae7a"

$.ajax({
type: 'GET',
cache: 'FALSE',
//contentType: "application/json",
url: "http://coverartarchive.org/release/"+uuid,
//data: jsonString,
statusCode: {
200: function () {
console.debug("200 for " + uuid);
},
307: function () {
console.debug("307 for " + uuid);
},
404: function () {
console.debug("404 for " + uuid);
},
0: function() {
console.debug("0 for " + uuid);
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.debug("error for " + uuid);
console.log(XMLHttpRequest);
}
});

您正在为 coverartarchive.org 编写代码吗?如果没有,它可能会被同源策略阻止。

关于jQuery - AJAX statusCode 方法未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17477738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com