I am using the follwing http request in my Angular JS code
$http.get('http://my url/.../')
.success(function(data, status, headers, config){
console.log('response',data);
})
.error(function() {
console.log('Error');
});
and in my node JS, I am using
response.write(data);
where can I get that data value. Because I am not getting the any console with the data. If I use
response.send(data);
then I am getting the console log from the my JS file with the data
The data is being sent in both cases. Only the send
method closes the connection.
The issues is that the success
callback only runs when the request completes . The write
method sends data to the client, but it does not complete the request. The client is still waiting for the server to say, " Okay, that's the whole message; there's no more to send. " Until the server does that, the success
callback won't run.
The send
method (and the end
method) close the connection. When the connection closes, the success
method runs.
it appears that you want to send a continuous stream of data (since you don't want to end the connection), in which case, you could log XHR progress
events . Unfortunately, the $http
interface does not currently expose progress
events .
I assume you are using Express with Node. With response.write
, you are just writing the response without sending it. You then have to call response.end
to say: "this response is ready, send it." response.send
writes and sends the response.
response.send(data);
is the same as:
response.write(data);
response.end();
It should simply be:
response.end(data);
You have to end it to flush the response.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.