Skip to content

Instantly share code, notes, and snippets.

Created June 15, 2016 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/c1e2b441197fee44aaf4851efd9fb16e to your computer and use it in GitHub Desktop.
Save anonymous/c1e2b441197fee44aaf4851efd9fb16e to your computer and use it in GitHub Desktop.
Scala.jsFiddle gist
import util._
import dom.ext._
import scala.scalajs.concurrent.JSExecutionContext.Implicits.runNow
object ScalaJSExample extends js.JSApp{
def main(): Unit = {
val url =
"http://jsonplaceholder.typicode.com/posts/1"
val f=Ajax.get(url)
f.onComplete{
case Success(xhr) =>
val json=js.JSON.parse(xhr.responseText)
val title=json.title.toString
val body=json.body.toString
println(div(
h1(title),
p(body)).render)
case Failure(e) => println(e.toString)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment