我一直在尝试让基本的 JSONP 在 Dart 中工作,但我被卡住了。读书this blog post还有这个this blog表明我应该使用 window.on.message.add(dataReceived);
获取 MessageEvent 并从事件中检索数据。
Dart 提示说“事件中没有这样的 setter/getter ‘消息’”。此外,我查找了获取 MessageEvent 的不同方式,但它似乎完全不相关(WebSockets?),并不是我真正需要的。
如果有人能解释发生了什么以及如何在 Dart 中真正使用 JSONP,那就太棒了!
最佳答案
您不再需要使用您指向的文章中描述的内容。您可以使用 dart:js :
import 'dart:html';
import 'dart:js';
void main() {
// Create a jsFunction to handle the response.
context['processData'] = (JsObject jsonDatas) {
// call with JSON datas
};
// make the call
ScriptElement script = new Element.tag("script");
script.src = "https://${url}?callback=processData";
document.body.children.add(script);
}
关于javascript - Dart 中的 JSONP 回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22726540/