Answer the question
In order to leave comments, you need to log in
How to correctly write nodejs in response to ajax request?
In general, the task is this - you need the ability to open and resave data in a file! I used to use ajax along with php, now I want to rewrite the server part with nodejs! but for some reason it doesn't work! I'm not particularly special in the server side, please explain how to do everything right :)
here is an example
$.ajax({
url: 'data.js',
type: 'POST',
data: {...}
});
var fs = require('fs');
fs.open("xxx.txt", "w+", 0644, function(err, file_handle) {
if (!err) {
fs.write(file_handle, 'xxxxxxxxxx', null, 'ascii', function(err, written) {
if (!err) {
fs.close(file_handle);
console.log("Файл сохранен.");
} else {
}
});
} else {
}
});
Answer the question
In order to leave comments, you need to log in
You need to raise the server first, something like this , and already write your code in the request handler
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question