1

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!

4

1 回答 1

2

我不知道这是否是正确的错误,但你有

print('request.responseText');

但这将打印文字文本request.responseText。这应该是

print(request.responseText);

?

我还会尝试运行 Fiddler 以查看从服务器返回的确切响应;为了判断问题出在服务器还是客户端代码上。

于 2014-08-20T16:55:22.273 回答