From 963a5da0f9cc187f17018aba7c866806582c364b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Doeraene?= Date: Sun, 27 Sep 2015 10:55:42 +0200 Subject: [PATCH] Use `null` by default for Ajax data, and map it to 0-arg send(). This is important for implementations of `XMLHttpRequest` that make a difference between an empty string argument, and no argument, such as, reportedly, Android mobile. --- .../scala/org/scalajs/dom/ext/Extensions.scala | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/scala/org/scalajs/dom/ext/Extensions.scala b/src/main/scala/org/scalajs/dom/ext/Extensions.scala index b265e0a0b..3e9188818 100644 --- a/src/main/scala/org/scalajs/dom/ext/Extensions.scala +++ b/src/main/scala/org/scalajs/dom/ext/Extensions.scala @@ -239,7 +239,7 @@ case class AjaxException(xhr: dom.XMLHttpRequest) extends Exception { } /** - * Wraps an XMLHttpRequest to provide an easy one-line way of making + * Wraps an XMLHttpRequest to provide an easy one-line way of making * an Ajax call, returning a Future. */ object Ajax { @@ -273,7 +273,7 @@ object Ajax { } def get(url: String, - data: InputData = "", + data: InputData = null, timeout: Int = 0, headers: Map[String, String] = Map.empty, withCredentials: Boolean = false, @@ -282,7 +282,7 @@ object Ajax { } def post(url: String, - data: InputData = "", + data: InputData = null, timeout: Int = 0, headers: Map[String, String] = Map.empty, withCredentials: Boolean = false, @@ -291,7 +291,7 @@ object Ajax { } def put(url: String, - data: InputData = "", + data: InputData = null, timeout: Int = 0, headers: Map[String, String] = Map.empty, withCredentials: Boolean = false, @@ -300,7 +300,7 @@ object Ajax { } def delete(url: String, - data: InputData = "", + data: InputData = null, timeout: Int = 0, headers: Map[String, String] = Map.empty, withCredentials: Boolean = false, @@ -313,7 +313,7 @@ object Ajax { data: InputData, timeout: Int, headers: Map[String, String], - withCredentials: Boolean, + withCredentials: Boolean, responseType: String): Future[dom.XMLHttpRequest] = { val req = new dom.XMLHttpRequest() val promise = Promise[dom.XMLHttpRequest]() @@ -331,7 +331,10 @@ object Ajax { req.timeout = timeout req.withCredentials = withCredentials headers.foreach(x => req.setRequestHeader(x._1, x._2)) - req.send(data) + if (data == null) + req.send() + else + req.send(data) promise.future } }