I am facing an issue with a button having an ID of 'tune-in' on a page named auth.ejs. The button is supposed to navigate to a new page called index.ejs when clicked.
However, instead of rendering the index page, clicking the button keeps me on the auth page. Nevertheless, the message "should display tune-in home page" is logged to the console.
On the HTML (ejs) page (located in the views folder > auth.ejs)
document.getElementById('tune-in').addEventListener('click', function() {
$.ajax({
type: 'GET',
url: '/tune-in',
success: function() {
console.log("should display tune-in home page");
}
});
}, false);
In the controllers folder > authController.js
app.get('/tune-in', function(req, res) {
res.render('index');
});
In the views folder > index.ejs This page contains regular HTML content and should render upon button click.
EDIT: index.js
var express = require('express');
var cookieParser = require('cookie-parser');
// The userController manages rendering the view and routing server requests
var authController = require('./controllers/authController');
var userController = require('./controllers/userController');
var app = express();
app.set('view engine', 'ejs');
app.use(express.static('./public'))
.use(cookieParser());
authController(app);
app.listen(process.env.PORT || 4000);
console.log("Listening on port 4000...");