经过多次尝试在 HttpRequest 中获取响应的内容后,我完全无法知道或理解为什么我不能拥有我想要的东西,我必须提到我只能在 onReadyStateChange(onLoad 和 onLoadEnd给我同样的结果!),但我真的想要回调之外的那个值。
这是我坚持的代码部分
Map responsData;
req=new HttpRequest()
..open(method,url)
..send(infojson);
req.onReadyStateChange.listen((ProgressEvent e){
if (req.readyState == HttpRequest.DONE ){
if(req.status == 200){
responsData = {'data': req.responseText};
print("data receaved: ${ req.responseText}");
//will log {"data":mydata}
}
if(req.status == 0){
responsData = {'data':'No server'};
print(responsData );
//will log {"data":No server}
}
}
});
//anything here to get responsData won't work