我不知道這是否是由於該JSON或JQuery的.getJSON()但是這個代碼不IE8工作/IE9。JSON/JQuery的.getJSON()在IE8/IE9不工作
我試圖從foursquare中獲取一些數據並顯示它。
它在Chrome,Firefox,Safari,Opera和IE10中正常工作。
JS
$(document).ready(function){
var url = "https://api.foursquare.com/v2/venues/4dab1ba55da3ba8a479999b2?oauth_token=ZKLARA2MZVA4VXES3VTMP2XJOVXE1X3OBJMBXMDFAB1NR0V4&v=20130305";
$.getJSON(url, function(response){
do{
var countNum = (response.response.venue.tips.count)-1;
var randomGroupNum = Math.floor((Math.random()*countNum)+0);
}while(typeof(response.response.venue.tips.groups[randomGroupNum])==="undefined");
var countItemNum = response.response.venue.tips.groups[randomGroupNum].count;
var randomItemNum = Math.floor((Math.random()*countItemNum)+0);
var mayorName = response.response.venue.mayor.user.firstName;
var mayorSurname = response.response.venue.mayor.user.lastName;
var mayorCount = response.response.venue.mayor.count;
var mayorPic = "https://is1.4sqi.net/userpix_thumbs"+response.response.venue.mayor.user.photo.suffix;
var text = response.response.venue.tips.groups[randomGroupNum].items[randomItemNum].text;
var time = new Date((response.response.venue.tips.groups[randomGroupNum].items[randomItemNum].createdAt)*1000);
var userName = response.response.venue.tips.groups[randomGroupNum].items[randomItemNum].user.firstName;
var userSurname = response.response.venue.tips.groups[randomGroupNum].items[randomItemNum].user.lastName;
var userPic ="https://is1.4sqi.net/userpix_thumbs"+response.response.venue.tips.groups[randomGroupNum].items[randomItemNum].user.photo.suffix;
$("#mayor_img").attr("src", mayorPic);
$("#mayor_name").append("<span style='font-weight:bold;'>"+mayorName+" "+mayorSurname+"</span>");
$("#mayor_check_in").append("<span>"+mayorCount+" check-ins in last 60 days</span>");
$("#last_tip_img").attr("src", userPic);
$("#last_tip_name").append("<span style='font-weight:bold;'>"+userName+" "+userSurname+"</span>");
$("#last_tip_comment").append("<span>"+text+"</span>");
});
});
Here is the fiddle of my JS and HTML。
這是由於IE8/IE9或其他?
您在瀏覽器上無法正常工作? – 2013-03-26 19:06:56
@dystroy它顯示沒有錯誤。 – Vucko 2013-03-26 19:07:39
如果你使用jQuery> 1.5,你可以使用'fail'方法來查看出了什麼問題。 – Johan 2013-03-27 09:43:33