views:

82

answers:

2

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").fadeOut('slow',function(){ $(this).remove(); }); },5000);
}
A: 

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.

Click Upvote
While the JSON string validates, I'm returning this via a coldfusion CFC in CF7. I've got a ton of white space being returned as well so I'm going to get that managed and see what happens.
CreativeNotice
A: 

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.

NilColor