I'm trying to issue an ajax request from my index view . .
├── app.js
|
├── package.json
├── ajax
│ ├──ajax.txt
|
├── home.ejs
- server is just renders the home page
app.set('views' , './');
app.set('view engine' , 'ejs');
app.get('/' , function(req , res){
res.render('01');
});
-ajax script loads fine in firefox without a server . - making an express server it give a 404
GET http://localhost:3000/ajax/ajax.txt 404 (Not Found)
- home simple issues a request when button is clicked .
var loadAjax = document.getElementsByTagName('button')[0];
loadAjax.addEventListener('click' , function(e){
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if((xhr.readyState == 4) && (xhr.status == 200 || xhr.status == 304)){
var rText = document.createTextNode(xhr.responseText);
var p = document.createElement('p');
p.appendChild(rText);
document.body.appendChild(p);
}
};
xhr.open('GET' , 'ajax/ajax.txt' , true);
xhr.send(null);