简体   繁体   English

jquery:IE8中的“异常抛出但未被捕获”,但在其他浏览器中有效

[英]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.

相关问题 IE8中的indexOf引发错误,但可在所有其他浏览器中使用 - indexOf in IE8 throwing error but works in all other browsers 有一个IE8的问题 - 一个完全适用于其他浏览器的脚本 - having an issue with IE8 - with a script that works on the other browsers perfectly jQuery在IE中不起作用,可在其他浏览器中使用 - jQuery not working in IE, works in other browsers 此JavaScript / jQuery代码是否会在ie8或其他浏览器中泄漏? - Does this JavaScript / jQuery code leak in ie8 or other browsers? 将JSON对象转换为knockout observable在IE8中不起作用,但适用于所有其他浏览器 - Converting JSON object to knockout observable not works in IE8, but works in all other browsers 该函数在所有浏览器中均有效,除了= &lt;ie8 - Function works in all browsers except =< ie8 jquery tablesorter不在输入/选择字段(IE8)上工作,在IE8中的所有其他文本字段上工作正常 - jquery tablesorter not working on input/select fields (IE8), works fine on all other text fields in IE8 IE8不能与jQuery .show()一起使用,并且不能在所有其他浏览器(包括ie9)上使用 - IE8 not working with jQuery .show() and working on all other browsers including ie9 jQuery .load在IE上不起作用(在所有其他浏览器上正常工作) - jQuery .load not working on IE (Works fine on all other browsers) jQuery $(this).parents(&#39;。cssClassName&#39;)仅在IE中找到窗口,但可在其他浏览器中使用 - jquery $(this).parents('.cssClassName') only finds window in IE, but works in other browsers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM