开发者

Deferred failed callback not calling

I am trying to figure out why the failed callback is not working for this deferred

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");
    });
});

I had a question Jquery deferred call back oddness that is similar but I figured this is different enough it should have it's own. Thanks again any help

Edit

After talking talking in t开发者_StackOverflow中文版he jQuery irc it looks like it my be a bug!


I commented in the other question but the problem is your url: it has two ? and it shouldn't

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

Should be

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

or even:

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

You could url encode the ? to %3F or use the second version and jQuery will url encode it for you.

UPDATE:- so i tested this on a view that returned a plain 500 internal server error. It worked fine: error callback ran fine.

Your url returns a 500 and a custom 500 error page. is there anyway to turn this off and try it again?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜