Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery $.post() function not working in IE unless developer tools is open

The jQuery $.post() function is not working in IE. I tried to open developer tools to see if I was getting a console error, but miraculously the function started working.

It is just a standard $.post() function

$.post('child_cb.php?type=check', { value: $(this).val() }, function(data) {
                        console.log(data);
                        if (data == 'true') {
                            $(".check_case").removeClass('bad').addClass('good');
                        }
                        else if (data == 'false') {
                            $(".check_case").removeClass('good').addClass('bad');
                        }
                    });

I see no reason why it wouldn't work.

like image 457
watzon Avatar asked Nov 28 '22 10:11

watzon


2 Answers

remove/comment out the console.log(data), IE cannot process this, it should work fine after you remove this. Had this problem myself recently.

like image 88
Anil Avatar answered May 10 '23 03:05

Anil


You should make a habit of using this for debugging so you don't forget the console.log :

if(!('console' in window) || ( ('console' in window) && !('log' in console) )){  
    window.console = {  
        log:function(e){  
            alert("You are using console log without the console!")  
        }  
    }  
}

you can remove the alert, but is ok if you want to be notified that you forgot something. :)

like image 30
cuzzea Avatar answered May 10 '23 01:05

cuzzea