2016-10-14 17 views
-2

我收到错误,console.log不是一个函数,但这并不是一个过去的问题。错误发生在第一个和第二个console.log,它不会通过那里。console.log不是一个函数 - 在javascript中的错误

我有分号,所以我不确定问题究竟是什么?

document.getElementById("fileToRead").addEventListener("change",function(event) { 
var input = document.getElementById("fileToRead"); 
//Variable for if statement to see if there is a header in the file. 
var headerType = false; 
console.log(input); 
input = event.target.files[0]; 

console.log('test'); 

    for(var i = 0; i < input.files.length; i++){ 
     var files = input.files[i]; 
      Papa.parse(files, { 
      header:headerType, 
      dynamictyping:true, 
      complete:function(results){ 
       console.log(results); 
       var input = results.data; 
       if(headerType === false){ 
        input.forEach(function(input){ 
         jsonData.theData = theData; 

         var singleEntry = { 
          "symbol" : input[0], 
          "date"  : input[1], 
          "open"  : input[2], 
          "high"  : input[3], 
          "low"  : input[4], 
          "close"  : input[5], 
          "volume" : input[6] 
          }; 

         jsonData.theData.push(singleEntry); 
         return jsonData; 
        }); // End forEach loop 
       } else { 

       } // End if statement for headerType 
       document.getElementById("editor").innerHTML = JSON.stringify(jsonData.theData); 
       } // End Callback Complete 

      }); // End PapaParse 
    } // End for loop 
}); 

我甚至注释掉的代码,所以这是最终的结果,它仍然说console.log不是一个函数!

// This is for the views/admin.ejs file only 
//This file describes how the Admin page works, hiding divs and working with  the data 
// importing 


var jsonData = {}; 
var theData = []; 

document.getElementById("fileToRead").addEventListener("change",function(event) { 
// var input = document.getElementById("fileToRead") 
// //Variable for if statement to see if there is a header in the file. 
// var headerType = false; 

// input = event.target.files[0]; 

console.log('test'); 

    // for(var i = 0; i < input.files.length; i++){ 
    //  var files = input.files[i]; 
    //   Papa.parse(files, { 
    //   header:headerType, 
    //   dynamictyping:true, 
    //   complete:function(results){ 
    //    console.log(results); 
    //    var input = results.data; 
    //    if(headerType === false){ 
    //     input.forEach(function(input){ 
    //      jsonData.theData = theData; 

    //      var singleEntry = { 
    //       "symbol" : input[0], 
    //       "date"  : input[1], 
    //       "open"  : input[2], 
    //       "high"  : input[3], 
    //       "low"  : input[4], 
    //       "close"  : input[5], 
    //       "volume" : input[6] 
    //       }; 

    //      jsonData.theData.push(singleEntry); 
    //      return jsonData; 
    //     }); // End forEach loop 
    //    } else { 

    //    } // End if statement for headerType 
    //    document.getElementById("editor").innerHTML = JSON.stringify(jsonData.theData); 
    //    } // End Callback Complete 

    //   }); // End PapaParse 
    // } // End for loop 
}); 
+0

你是如何运行这段代码的?如果在浏览器中,哪个浏览器/版本? – Amy

+0

Chrome 53.0.2785.143 – illcrx

+0

是这个代码块导致错误? – Dummy

回答

0

我把控制台重新定义为更深层次的代码!完成新手错误......希望我不会再犯这个错误。

相关问题