Am using a function to save data. Using the http.request
option. It is working fine. If I call the same function in a loop, some of the data not saving in database. Also getting the parse error message for some response.
How Can I call the function of http.request
in a loop?
for (var i = 1; i <= 23; i++) {
turn_timer(i);
}
function turn_timer(nos) {
try {
var str = "num=" + nos;
var len = str.length;
win_settings.headers = {
'Content-length': len,
'Content-Type': 'application/x-www-form-urlencoded'
}
var request = http.request(win_settings, function(response) {
response.on('data', function(data) {
});
response.on('error', function(err) {
});
response.on('end', function() {
});
});
request.on('error', function(err) {
});
request.write(str + "\0");
request.end();
} catch (err) {
console.log(err);
}
}