使用新的FormData()在Dart中发送HttpRequest

时间:2014-02-19 21:44:31

标签: forms dart httprequest

有人可以解释如何在Dart中使用new FormData()将表单数据发送到HttpRequest的服务器?获取和格式化数据的任何替代方法?

1 个答案:

答案 0 :(得分:4)

这是一个基本的例子:

final xhr = new HttpRequest();
xhr.open('POST', url);
xhr.onReadyStateChange.listen((e) {
  if (xhr.readyState == 4 && xhr.status == 200) {
    // on OK
  }
});

// send datas by specifying each element
xhr.send(new FormData()
  ..append('field1', x1)
  ..append('field2', x2)
);

// send datas by using an existing form and adding some additional datas
xhr.send(new FormData(formElement)
  ..append('field1', x1)
);