1

我试图弄清楚为什么失败的回调不适用于这个延迟

http://jsfiddle.net/austinbv/wzve6/6/

get_each_total = function(callback) {
    var requests;
    requests = [];
    var url;
    url = "http://otter.topsy.com/search.js?callback=?&apikey=38A260E9D12A4908B1AF9184B691131&q=justin+bieber&window=d";
    requests.push($.getJSON(url, function(data) {}));
    $.when.apply($, requests).then(function() {
        callback();
    }, function() {
        alert("There was an error communicating with a remote library, try again in a few");
    });
};

get_each_total_broken = function(callback) {
    var requests;
    requests = [];
    var url;
    url = "http://otter.topsy.com/hjhkl/sehjkhhkjhkarch.js?callback=?&apikey=38A260E9D12A4908B1AF9184B691131&q=justin+bieber&window=d";
    requests.push($.getJSON(url));
    $.when.apply($, requests).then(function() {
        callback();
    }, function() {
        callback();
    });
};

$(function() {
    get_each_total_broken(function() {
        alert("fail");
    });
});

我有一个类似的问题Jquery 延迟回调奇怪,但我认为这已经足够不同了,它应该有它自己的。再次感谢任何帮助

编辑

在 jQuery irc 中交谈之后,它看起来像是一个错误!

4

1 回答 1

1

我在另一个问题中发表了评论,但问题是您的网址:它有两个?,不应该

url = "http://otter.topsy.com/hjhkl/sehjkhhkjhkarch.js?callback=?&apikey=38A260E9D12A4908B1AF9184B691131&q=justin+bieber&window=d";

应该

url = "http://otter.topsy.com/hjhkl/sehjkhhkjhkarch.js?callback=somevalue&apikey=38A260E9D12A4908B1AF9184B691131&q=justin+bieber&window=d";

甚至:

url = "http://otter.topsy.com/hjhkl/sehjkhhkjhkarch.js"
$.getJSON(url, {
    "callback": "somevalue",
    "apikey": "38A260E9D12A4908B1AF9184B691131",
    "q": "justin bieber",
    "window": "d"
}, function(data){ alert("Got: " + data);});

您可以对?to进行 url 编码%3F或使用第二个版本,jQuery 将为您进行 url 编码。

更新:-所以我在一个返回普通 500 内部服务器错误的视图上对此进行了测试。它运行良好:错误回调运行良好。

您的网址返回 500 和自定义 500 错误页面。有没有办法把它关掉再试一次?

于 2011-09-02T05:26:52.677 回答