In my server file I am trying to send over data from a txt file and receive it in ajax like so
app.get('/send', function(req, res) {
showData = fs.readFile('file.txt', 'utf8', function(err, data) {
res.send({data:data})
})
})
It reaches my ajax code and I want to append it to my html but I am unable to
console.log(response.data)
response.dataata.forEach(function(val) {
console.log(val.id)
tbodyEl.append('\
<tr>\
<th class="id">' + val.id + '</th>\
</tr>\
')
})
When I send through just a normal json variable from my server file it works but when I try use the text file it doesn't (saying TypeError: response.data.forEach is not a function )
via Sprout
No comments:
Post a Comment