[英]jquery: “Exception thrown and not caught” in IE8, but works in other browsers
My code works fine in other browsers, but in IE8 I get "error on page" - and when I click that it says: "Exception thrown and not caught Line: 16 Char: 15120 Code: 0 URI: http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js " 我的代码在其他浏览器中工作正常,但在IE8中我得到“页面上的错误” - 当我点击它时说:“抛出异常而未捕获行:16个字符:15120代码:0 URI: http:// ajax。 googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js “
I tried linking to jquery.js (rather than jquery.min.js) and to 1.5.1/jquery.min.js, but problem still remains. 我尝试链接到jquery.js(而不是jquery.min.js)和1.5.1 / jquery.min.js,但问题仍然存在。
Can someone correct/improve my code for me, or guide me as to where to look. 有人可以为我纠正/改进我的代码,或指导我去哪里看。 Thanks
谢谢
<script type="text/javascript">
function fbFetch()
{
var token = "<<tag_removed>>&expires_in=0";
//Set Url of JSON data from the facebook graph api. make sure callback is set with a '?' to overcome the cross domain problems with JSON
var url = "https://graph.facebook.com/<<ID_REMOVED>>?&callback=?&access_token=" + token;
//Use jQuery getJSON method to fetch the data from the url and then create our unordered list with the relevant data.
$.getJSON(url, function(json)
{
json.data = json.data.reverse(); // need to reverse it as FB outputs it as earliest last!
var html = "<div class='facebook'>";
//loop through and within data array's retrieve the message variable.
$.each(json.data, function(i, fb)
{
html += "<div class='n' >" + fb.name;
html += "<div class='t'>" + (dateFormat(fb.start_time, "ddd, mmm dS, yyyy")) + " at " + (dateFormat(fb.start_time, "h:MMtt")) + "</div >";
html += "<div class='l'>" + fb.location + "</div >";
html += '<div class="i"><a target="_blank" title="opens in NEW window" href="https://www.facebook.com/pages/<<id_removed>>#!/event.php?eid=' + fb.id + '" >more info...</a></div>';
html += "</div >";
}
);
html += "</div>";
//A little animation once fetched
$('.facebookfeed').animate({opacity: 0}, 500, function(){
$('.facebookfeed').html(html);
});
$('.facebookfeed').animate({opacity: 1}, 500);
});
}; };
Does the code do the job in IE8 or does it break? 代码是在IE8中完成工作还是破坏了? The reason I ask is because if it works as expected you could just wrap it in a
try{ } catch{ \\\\do nothing }
block and put it down to another thing IE is rubbish at. 我问的原因是因为如果它按预期工作,你可以将它包装在
try{ } catch{ \\\\do nothing }
块中,并将其归结为另一件事IE是垃圾。
You may be better off creating an object for the creation of the facebook div. 你可能最好创建一个用于创建facebook div的对象。 Something like...
就像是...
var html = $('<div />');
html.attr('class', 'facebook');
Then in your each loop you can do this... 然后在你的每个循环中你可以做到这一点......
$('<div />').attr('class', 'n').append(fb.name).appendTo(html);
$('<div />').attr('class', 't').append etc...
Then append html
to the facebookfeed
object 然后将
html
附加到facebookfeed
对象
Doing this may remove the scope for error when using single quotes and double quotes when joining strings together, which in turn may solve your issue in IE8 这样做可能会在将字符串连接在一起时使用单引号和双引号时删除错误范围,这反过来可能会解决您在IE8中的问题
$('.facebookfeed').fadeOut(500, function(){
$(this).append(html).fadeIn(500);
});
Hope this helps! 希望这可以帮助!
UPDATE UPDATE
The append method is used to add stuff to a jquery object. append方法用于向jquery对象添加内容 。 For more info see here
有关详情,请参阅此处
So to surround the div's as you mentioned in the comments you would do something like this... 所以如你在评论中提到的那样围绕div,你会做这样的事情......
var nDiv = $('<div />').attr('class', 'n').append(fb.name);
$('<div />').attr('class', 't').append(fb.somethingElse).appendTo(nDiv);
// etc
And then you would need to append that to the html div like so... 然后你需要将它附加到html div这样......
html.append(nDiv);
So that would give you 这样会给你
<div class="facebook">
<div class="n">
value of fb.name
<div class="t">
value of fb.somethingElse
</div>
</div>
</div>
So what you have done is created a new jquery object and appended to that, then appended that to the html object which you have then appended to the facebookfeed div. 所以你所做的是创建一个新的jquery对象并附加到该对象,然后将其附加到html对象,然后将其附加到facebookfeed div。 Confusing huh?!
令人困惑啊?!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.