I get this error: TypeError: undefined is not an object (evaluating 'table[0][3]') every time and none of my JQuery works. If I run my server as localhost there is not problem, but it occurs when it's on the real server. Error message
Here is my code snippet and the row I get the error on:
$(document).ready(function() {
$('#number-of-ratings1').text(table[0][3]);
}
I really don't understand why this error occurs. Any help will be appreciated. Thank you very much in advance!
EDIT: my app.js file:
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');
});
My 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]);
}