I have been trying to get this working
var http = require('http'),
parseString = require ('xml2js').parseString;
for (var noOfZones = 1; noOfZones<=8; noOfZones++) {
var newPath = 'http://192.168.1.200/getZoneData?zone='+noOfZones;
var req = http.request(newPath, function(zres, noOfZones) {
zres.setEncoding('utf8');
zres.on('data', function (zonedata) {
parseString(zonedata, {
trim:true,
childkey:9,
explicitArray:false,
explicitChildren:false
}, function (err, zones) {
console.log(noOfZones);//this one bring back undefined
});
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message)
})
req.end();
}
The for loop works ok for passing the noOfZones to newPath. However the value is not being passed through within the function (err, zones) I have been reading on passing the variables to inline functions and attempted to place it at various levels but it doesn't seem to be working for me. All I get back is undefined. (Even if i stringify it)