0
//我无法从https.get中获取数据到变量中 //我们需要将httpd返回值指定给global.city变量。Nodejs - 问题与响应
global.city ;
https.get(url, function(response) {
var body ='';
response.setEncoding("utf8");
response.on('data', function(chunk) {
body += chunk;
//console.log(body);
});
}).on('error', function(e) {
console.log("Got error: " + e.message);
}).on('response',function(f){
console.log("lets dance");
}).on('end', function() {
var places = JSON.parse(body);
locations = places.results;
return locations ;
global.city = locations ; // I get the data here.
console.log(global.city);
/* the data is seen here */
});;
console.log(global.city); // No response outside the function.