summaryrefslogtreecommitdiff
path: root/examples/demos/src/main/scala/webpage/Weather2.scala
blob: bf908e37024a526a3b603f3fb263ffdce2e37c12 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package webpage

import org.scalajs.dom
import org.scalajs.dom.{Node, Element}
import scalajs.js
import scalajs.js.annotation.JSExport
import scalatags.JsDom.all._

@JSExport
object Weather2 extends{
  @JSExport
  def main(target: dom.HTMLDivElement) = {
    import dom.extensions._
    import scala.scalajs
                .concurrent
                .JSExecutionContext
                .Implicits
                .runNow

    val url =
      "http://api.openweathermap.org/" +
      "data/2.5/weather?q=Singapore"

    Ajax.get(url).onSuccess{ case xhr =>
      target.appendChild(
        pre(
          js.JSON.stringify(
            js.JSON.parse(xhr.responseText),
            space=4
          )
        ).render
      )
    }
  }
}