开发者

Trouble Shoot JavaScript Function in IE

So this function works fine in geko and webkit browsers, but not IE7. I've busted my brain trying to spot the issue. Anything stick out for you?

Basic premise is you pass in a data object (in this case a response from jQuery's $.getJSON) we check for a response code, set the notification's class, append a layer and show it to the user. Then reverse the process after a time limit.

function userNotice(data){
    // change class based on error code returned
    var myClass = '';
    if(data.code == 200){ myClass='success'; }
    else if(data.code == 400){ myClass='error'; }
    else{ myClass='notice'; }
    // create message html, add to DOM, FadeIn
    var myNotice = '<div id="notice" class="ajaxMsg '+myClass+'">'+data.msg+'</div>';
    $("body").append(myNotice);
    $("#notice").fadeIn('fast');
    // fadeout and remove from DOM after delay
    var t = setTimeout(function(){ $("#notice").fa开发者_如何学JAVAdeOut('slow',function(){ $(this).remove(); }); },5000);
}


I suggest you look into the JSON output returned by the server. When .getJSON() doesn't call the callback function as expected, it is usually because the JSON returned by the server is broken somewhere.


This code works in IE8 (doesn't have IE7 but also try in compat mode) using stub data

var d = {code:200, msg:'lorem ipsum'}
userNotice(d);

So i think you should check JSON you get from server. Does it have all keys you use? Oh! And check for something like this kind of dict/json you get from server: {key_one: 'value', key_two: 'value',}. Notice last comma -- this can be a problem in IE.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜