Hi I want to update/create a datatable from results of a function. I have the following code and I now need to output the results into a datatable. At the top of the page I have :

<script type="text/javascript">

    $('#example').dataTable( {

    paging: false,

    searching: false

    } );


and lower in the page I have:

     myCtx.executeQueryAsync(function () {
            if (queryItemCollections.length == 0) {
                console.log("collection empty");
            queryItemCollections.forEach(function (item) {
                // do work with individual list items here

$('#example').dataTable().fnAddData( [ 'a','b'] );


        }, genericFailHandler);

When I add $('#example').dataTable().fnAddData( [ 'a','b'] ); in the function the table does not update however when I add code outside the function it updates. Oddly, when I call up developer tools it renders. What the best way to fix this?

UPDATE: I commented console.log and now it works.. any ideas why this could be causing the issue?

  • 1
    Which browser are you using ?? For eg: in IE9 console.log works only when developer tools is open ie in debug mode. In normal mode IE9 throws error for console.log
    – Unnie
    Oct 29 '15 at 16:36
  • Using IE11. Somehow console log is affecting the jquery? Oct 30 '15 at 8:59
  • Yes sometimes in IE11 , if the default Document mode is IE9 then console.log won't work. Press F12 and check what is the default document mode
    – Unnie
    Oct 30 '15 at 9:01
  • Document mode is IE9 (F12) Oct 30 '15 at 10:09
  • Yes so console.log won't work in that mode. There is no problem with your code logic, just remove console.log or check for typeof (console) == "undefined" before using it
    – Unnie
    Oct 30 '15 at 10:22

In terms of your issue, IE 8/9 will throw a script error (when using console.log), if you do not have the console open (because it can not find the console object). You can overcome this by some additional logic. The below logic, I've used in a web application where I leverage the web configuration to choose whether or not I want to display the console logs (in certain environments), but would no longer throw the error. This issue should only occur for IE 8/9.

var debugging = false; 

if ( -- add some conditional logic here  --) 
    debugging = true; 

if (typeof console == "undefined") 
    var console = { log: function () { } }; 
else if (!debugging || typeof console.log == "undefined") 
    console.log = function () { };

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.