繁体   English   中英

TypeError:未定义不是对象(正在评估“ table [0] [3]”)

[英]TypeError: undefined is not an object (evaluating 'table[0][3]')

我收到此错误:TypeError:每次都不是undefined(评估'table [0] [3]'),并且我的JQuery都不起作用。 如果我以本地主机身份运行服务器,则不会出现问题,但是当它在真实服务器上时会发生。 错误信息

这是我的代码段以及发生错误的行:

$(document).ready(function() {

    $('#number-of-ratings1').text(table[0][3]);

}

我真的不明白为什么会发生此错误。 任何帮助将不胜感激。 提前非常感谢您!

编辑:我的app.js文件:

var fs = require('fs');
const log=require('simple-node-logger').createSimpleLogger();
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
var port = process.env.PORT || 8081;

app.use(express.static(__dirname + '/server'));
app.use(express.static(__dirname + '/public'));

app.use('/images', express.static(__dirname +'/images'));

app.get('/', function(req, res){
    res.sendFile('main.html');
});

app.listen(port, function(){
    console.log('Server is running on port:' + port);
});

app.post('/submit', function(req, res){
 console.log(req.body.rank);
 return res.sendFile('success.html');
});

我的JQuery:

var table = [];
var row = [];

$.get('data.txt', function(data) {

   var bigarray = data.split('-');
   bigarray.forEach(function(currRow){
     currentRow = currRow.split(';');
     table.push(currentRow);
   });
}, 'text');


$(document).ready(function() {
   $('#number-of-ratings1').text(table[0][3]);
}

输入代码

$('#number-of-ratings1').text(table[0][3]);

在bigarray.forEach完成之后。

$.get('data.txt', function(data) {

   var bigarray = data.split('-');
   bigarray.forEach(function(currRow){
      currentRow = currRow.split(';');
      table.push(currentRow);
   });
   $('#number-of-ratings1').text(table[0][3]);
}, 'text');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM