阅读 XMLHttpRequest 以用于 Google Chrome 扩展程序,我遇到了一个问题。
MDN specifies using XMLHttpRequest.addEventListener
, 而 Google uses XMLHttpRequest.onreadystatechange
在他们的例子中。
这两种方法之间是否有偏好向 Google Apps 脚本发出 GET 请求时?我是异步 Javascript 的新手,在此之前我一直在 GAS 工作。
最佳答案
首选将是浏览器兼容性。来自 MSN 上的 XMLHttpRequest API 文档。
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#Properties
onreadystatechange
as a property of theXMLHttpRequest
instance is supported in all browsers.
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#Events
More recent browsers, including Firefox, also support listening to the
XMLHttpRequest
events via standardaddEventListener
APIs in addition to settingon*
properties to a handler function.
由于 Apps Script Web Apps 很快将只支持现代浏览器(因为 native 和模拟模式已弃用),您可以使用其中任何一种。
关于google-chrome-extension - XMLHttpRequest.onreadystatechange 与 addEventListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34905828/