2

I am trying log json data onto console using following code and I want to debug it using developers tool provided by IE.

My Code is

$.getJSON("s13.aspx", function (data3, textStatus3) {
                     console.log(textStatus3);}

But I am having error that console is undefined.

Why is it happening? How to solve it?

  • console.log working only if you open developer tool (F12) [MS-Documentation about](http://msdn.microsoft.com/en-us/library/dd565625%28v=vs.85%29.aspx#consolelogging) – Frogmouth Dec 20 '13 at 11:51

2 Answers2

2

Use if(window.console) first.

if( window.console ){
   console.log('hi');
}else{
   alert('console not avaliable');
}

https://developer.mozilla.org/en-US/docs/Web/API/console

Eduardo Stuart
  • 2,679
  • 15
  • 21
1

console doesn't exist in IE unless the console is actually open

check this link for a detailed discussion:

Internet Explorer: "console is not defined" Error

to check whether console is defined or not, you can do

if ('console' in window)
Community
  • 1
  • 1
gaurav5430
  • 9,899
  • 5
  • 32
  • 73