2017-08-26 94 views
0
const http = require('http'); 

const request = http.get('http://localhost:90/rentflig/ajaxfetchproperties.php', response => { 

    console.log(response.statusCode); 

    let body = ""; 

    response.on('data', data => { 
    body += body.toString(); 
    }); 
    response.on('end',() => { 

    var getData = JSON.parse(body); 
    console.log(getDate.LocationName); 

    }); 

}); 

回答

-1

你的意思是data.toString()

response.on('data', data => { 
    body += data.toString(); 
}); 
+0

非常感謝。現在解決了。 – Emmanuel

0

其實你在哪裏相當接近,但有一些缺件在你的代碼

let body = []; 
request.on('data', (chunk) => { 
    body.push(chunk); 
}).on('end',() => { 
    body = Buffer.concat(body).toString(); 
    // at this point, `body` has the entire request body stored in it as a string 
    const json = JSON.parse(body); 
    console.log(json); 
}); 
+0

明白了。非常感謝。 – Emmanuel

+0

很高興幫助@Emmanuel –

相關問題