Javascript working in Internet Explorer (IE 11) Developer Mode Only

8/6/2015


Whose the developer who has not read an api and said..hahn i can trick it to do what i do because i am fucking genius at what i do?  Well this is that post, only that, in my case i did it with Internet Explorer. And if you have worked with browsers, you know IE is that old irascible grand aunt you just dont want to mess up with


While using the "$Interval" service of Angular, I was calling a function 'StoreAnswer' repeatedly to make an ajax call to save the data. The "$Interval" is actually a wrapper for $SetInterval function of JS.  Something like 


function OnSaveButtonClick(){
  $Interval(function () { StoreAnswers();}, 0 );
}

$scope.StoreAnswers = function()
{
  //ajax call
}

and here is where the madness starts, the code works perfectly well on Chrome, firefox etc.  On IE it works fine only if developer toolbar is open otherwise, it just calls the StoreAnswers once and then does nothing...sits and it does not even hang. 

Turns out the culprit is the second parameter to $Interval function ( the millisecond JS waits before calling the function again). I was developing on Chrome (and it let me be smart ) set this parameter to 0 seconds.
It worked fine and within  a day i forgot my logical stupidity. Setting it to 1, made the code working on IE also.

Hope someone's time is saved by this


Name

Email

WebSite