Using NodeJS with Express server, when you go to http://localhost:(Serverport), the NodeJS server responds with sending an HTML file using the following code:
app.get('/', function(req, res){
res.sendFile(__dirname + '/login.html');
});
Now I am using a JQuery AJAX POST to send info to the server and based on the servers response send the user to either HTML page "/index" or if user credentials aren't good, HTML page "/loginno". The problem is AJAX isn't playing nice with the server response of sendfile
like in the server get function response.
I am getting the file from the server and it prints out the complete HTML in the console, but I just don't know how to make the browser actually go to the page the same way it does with a server GET response.
This is my Ajax function that works and gets the HTML page object from the server, but the browser just doesn't navigate to the page.
$.ajax({
type: "POST",
url: '/index', //A string containing the URL to which the request is sent.
timeout: 2000,
//A plain object or string that is sent to the server with the request.
data: userdata,
//The type of data expected from the server. Default: Intelligent Guess (xml, json, script, text, html).
dataType: 'html',
success: function(response,status,xhr) {
//show content
console.log('Success!' + response+', Status: '+status+', xhr: '+xhr)
},
error: function(jqXHR, textStatus, err) {
//show error message
alert('text status '+textStatus+', err '+err)
}
});
So the question is, how do you tell a JQuery AJAX POST function to navigate to an HTML page object sent from an NodeJS server response?