开发者

Jquery - getJSON 401 "bug?"

i have a problem with the jquery getjson.

This code works

$.getJSON('http://twitter.com/status/user_timeline/USERNAME.json?count=10&callback=?', function(twitter_dat开发者_运维知识库a)
{
    alert('works');          
});  

and this code not?

$.getJSON('https://api.twitter.com/1/account/verify_credentials.json?callback=?', function(twitter_data)
{
   alert('no alert ?');
}); 

But why? Any ideas?

example - > http://jsfiddle.net/4wWJW/2/

Thanks in advance!

Peter


I've updated a version of your code here: http://jsfiddle.net/4wWJW/9/

Unfortunately the example you give includes a oauth_nonce which I believe is a one-time authentication token. So unfortunately this won't work. You'll need to be authenticated with your account to debug.

Instead of using jQuery.getJSON I've used the long-hand call to jQuery.ajax. This allows an error handler to be used. When the ajax call succeeds the success function is called, otherwise the error function is called.

I can see in this case that the call is not successful, e.g. a status code of 200 is not returned, and therefore the error function is called.

You could interrogate the jqXHR object and the other parameters to the error function to see what is happening.


https://api.twitter.com/1/account/verify_credentials.json returns 401 status code. You didn't send any credentials in the request.


from jQuery

Important: As of jQuery 1.4, if the JSON file contains a syntax error, the request will usually fail silently. Avoid frequent hand-editing of JSON data for this reason. JSON is a data-interchange format with syntax rules that are stricter than those of JavaScript's object literal notation. For example, all strings represented in JSON, whether they are properties or values, must be enclosed in double-quotes.

I would guess that returning an error would be equivalent to returning invalid JSON as far as jQuery is concerned?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜