Skip to content

Instantly share code, notes, and snippets.

@sebnozzi
Created January 10, 2016 18:51
Show Gist options
  • Save sebnozzi/402873647d5b8036729c to your computer and use it in GitHub Desktop.
Save sebnozzi/402873647d5b8036729c to your computer and use it in GitHub Desktop.
val jsonStrToSend = ""
val serverUrl = ""
def handleAjaxError(jqXHR: JQueryXHR, textStatus: String, errorThrow: String): Unit = {
println("Error while performing AJAX POST")
}
def handleAjaxSuccess(data: js.Any, textStatus: String, jqXHR: JQueryXHR): Unit = {
val jsonFromServer = jqXHR.responseText
println(s"Got from server: $jsonFromServer")
}
val ajaxSettings = js.Dynamic.literal(
url = serverUrl,
contentType = "application/json",
data = """{"input": "hello"}""",
`type` = "POST",
success = handleAjaxSuccess _,
error = handleAjaxError _).asInstanceOf[org.scalajs.jquery.JQueryAjaxSettings]
jQuery.ajax(ajaxSettings)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment