Answer the question
In order to leave comments, you need to log in
Why is the page not changing again on nodejs?
I can’t understand one moment, I wrote the processing of url parameters if it’s empty, display index.html if not, then error.html
function onRequest (request, response) {
var parse = urlutils.parse(request.url, true);
view(parse.pathname, parse.query.text, function (render) {
response.writeHead(200, {"Content-Type": "text/html"});
response.write(render);
response.end();
// console.log('write ' + parse.pathname);
});
}
Answer the question
In order to leave comments, you need to log in
function view(page, text, callback) {
if (page === '/') {
action = 'render';
page = 'index';
} else if (page === '/ajax') {
translate(text, function (result) {
callback(result);
});
return;
} else {
action = 'render';
page = 'error';
}
if (action = 'render') {
callback(fs.readFileSync('front/' + page + '.html'));
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question