Hopefully I'm posting correctly.I have a Node Js local server and several identical html pages. On every page I save some user data input fields saved simply on a text file. My problem is that if the users refresh the page the data from the previous html page is send again and again saved on the text file. Is there a way to prevent this?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 || 8000;app.use(express.static(dirname + '/server')); app.use(express.static(dirname + "/public")); app.use('/images', express.static(__dirname +'/images'));app.listen(port, function(){ console.log('server is running on ' + port); });app.get('/', function(req, res){ res.sendfile('intro.html'); });app.post('/userID', function(req, res){ //save the userID on a text file var userID= req.body.userID + ';'; var data = fs.appendFileSync('temporary/userID.txt', userID, 'utf8');return res.sendfile('main.html'); });app.post('/submit', function(req, res){res.sendfile('main2.html'); }); Furthermore, I have also a refresh button that does the same as the browser refresh button. I s there a way to avoid the same problem? and its JavaScript:document.addEventListener('DOMContentLoaded', function () { document.querySelector('button').addEventListener('click', clickHandler); });function clickHandler(element) { location.reload(); } Thank you in advance!
Submitted April 17, 2018 at 02:21PM by rulli123
No comments:
Post a Comment