Synchronous XHR Extension
Closed this issue · 1 comments
exoego commented
I want to send XHR to server on window unload.
For such purpose, modern browsers added sendBeacon
API which is experimentally available in scala-js-dom.
However, I need fallback to synchronous XHR like this for legacy browsers that does not support sendBeacon
API.
It would be helpful if Ajax extension has async
argument, so that one can use synchronous XHR if necessary.
def apply(method: String, url: String, data: InputData, timeout: Int,
headers: Map[String, String], withCredentials: Boolean, responseType: String,
async: Boolean = true /* THIS*/ ): Future[dom.XMLHttpRequest] = {
...
req.open(method, url, async /* THIS */)
sjrd commented
The methods in Ajax
return Future
s. It makes no sense to allow synchronous requests in these methods, because you wouldn't be able to access the result synchronously anyway. If you want synchronous AJAX requests, I suggest you build your own abstraction on top of dom.XMLHttpRequest
. It is out of scope for the Ajax
extension in this repo.