如何在Dart中使用asAX = true的AJAX

前端之家收集整理的这篇文章主要介绍了如何在Dart中使用asAX = true的AJAX前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我找到了一个 XMLHttpRequest的 reference
final req = new XMLHttpRequest();
  req.open('GET','${Sections.home}/data/$name',false);
  req.send();
  _htmlBody = req.responseText;

Full Source

但这是为了async = false,是否有一个async = true的工作示例?

https://code.google.com/p/dart/source/browse/branches/bleeding_edge/dart/samples/belay/bcap/bcap_client.dart有一个例子
void privateInvoke(String ser,String method,String data,SuccessI ski,FailureI fki) {
    if (urlRegex.hasMatch(ser)) {
      var req = new XMLHttpRequest();
      req.open(method,ser,true);
      req.on.readyStateChange.add(void _(evt) {
        if (req.readyState == 4) {
          if (req.status == 200) {
            ski(req.responseText);
          } else {
            fki(new BcapError(req.status,req.statusText));
          }
        }
      });
      req.send(data);
      return;
    } else {
      super.privateInvoke(ser,method,data,ski,fki);
    }
  }

也是https://code.google.com/p/dart/source/browse/branches/bleeding_edge/dart/client/samples/total/src/ServerChart.dart中的另一个异步示例

XMLHttpRequest request = new XMLHttpRequest();
request.on.readyStateChange.add((Event event) {
  if (request.readyState == XMLHttpRequest.DONE && request.status == 200) {
    callback("data:image/png;base64,${StringUtils.base64Encode(request.responseText)}");
  }
});
...
request.open("POST",url,true,null,null);
request.setRequestHeader("Content-type","text/plain");
request.overrideMimeType("text/plain; charset=x-user-defined");
print("Chart request: ${data}");
request.send(data);
原文链接:https://www.f2er.com/ajax/159999.html

猜你在找的Ajax相关文章