I'm trying to have to have an ajax call from my home page, but it's already rerouted to index.html. So here's what I'm doing. This is my ajax call...var xhr = new XMLHttpRequest(); xhr.open('GET', "http://localhost:4000" + "?fetching=true", true); xhr.onload = function(){ if(this.status==200){ //stuff } } xhr.send(); and then on the server side (app.js) I separate GET requests with the fetching query and the ones without...app.get('/', function(req, res){ if (req.query.fetching){ //do stuff } else { res.sendFile(__dirname + '/index.html'); } }); Is this good practice? Is it the standard way of doing this? And is there so I can direct ajax GET request somewhere other than app.js. I've tried http://localhost:4000/submit but it never works unless it directs to the main localhost path (app.js)
Submitted August 04, 2018 at 12:14AM by Hellaimportantsnitch
No comments:
Post a Comment