开发者

Catch $.getJSON error

I've been trying to figure this out for hours. I 开发者_Python百科have a DYNAMIC youtube search, which I use Youtube's JSON api for. It works usually, but there are times that it won't find anything. Is there a way to figure out if it finds nothing, and then end the function because otherwise it stops the entire code. I tried jsonp, but that didn't seem to be correct. Somewhere I read that error catching is built into the newest jQuery getJSON, but I couldn't find it.

The code is really tedious so I'd rather not post it unless it comes to that. I'd appreciate any help! Thanks guys.

error showing that json didn't return anything

jquery-1.4.4.min.js:32 TypeError: Result of expression 'j' [undefined] is not an object.

http://pastebin.com/4rVjAUwa


Did you tried just using of jsonp or using of jQuery.get and then parse output if it is not nothing?


If you need to catch error situations, use $.ajax with error property:

$.ajax({
  url: url,
  dataType: 'json',
  data: data,
  success: callback,
  error: callback
});


I figured it out, all I had to do was:

if (data.feed.entry == null)

before the .each() to catch the error.


sorry but I have not privilege to comment. You cannot extract data from remote server with json. have you tried jsonp? it is

http://gdata.youtube.com/feeds/api/videos?max-results=5&alt=json&q=phish&callback=?
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜