In a previous question here the server side dart file is calling a FUTURE email function that return either a confirmation msg or an error. the function below is working fine for the "print" function, but for the "res.write" is not working.
the server.dart file:
void handlePost(HttpRequest req) {
HttpResponse res = req.response;
print('${req.method}: ${req.uri.path}');
addCorsHeaders(res);
req.listen((List<int> buffer) {
SendConfirmationNote2Client(String msg) {
print('msg: $msg'); // this is working
res.write(msg); // this looks to be wrong!
res.close();
}
email()
.then(SendConfirmationNote2Client);
}, onError: printError);
}
the client.dart file is:
void submitFprm(){
request = new HttpRequest();
request.onReadyStateChange.listen(onData);
var url = 'http://127.0.0.1:4040/';
request.open('POST', url);
request.send(JSON.encode(theData));
}
void onData(_) {
if (request.readyState == HttpRequest.DONE && request.status == 200) {
print('request.responseText'); // this is not printing anything!!
server_output.innerHtml=request.responseText; // this working
} else if (request.readyState == HttpRequest.DONE &&
request.status == 0) {
print('no server');
}
}
any help!