문제

On my app, I need to make some ajax calls and I am trying to use jQuery for it.

The way to do it would be by passing an object of type JQueryAjaxSettings to jQuery.ajax(url: String, settings: JQueryAjaxSettings). But I could not find a way to instantiate such an object.

I have tried to inherit the class with an object, a simple class, but none of these will work.

What's the way to go on this?

도움이 되었습니까?

해결책

You will have to use js.Dynamic.literal to construct the settings arguments, and cast it to the appropriate type, like this:

import scala.scalajs.js
import org.scalajs.jquery._

jQuery.ajax(js.Dynamic.literal(
    url = "http://www.w3.org/People/Berners-Lee/card",
    success = { (data: js.Any, textStatus: js.String, jqXHR: JQueryXHR) =>
      console.log(s"data=$data,text=$textStatus,jqXHR=$jqXHR")
    },
    error = { (jqXHR: JQueryXHR, textStatus: js.String, errorThrow: js.String) =>
      console.log(s"jqXHR=$jqXHR,text=$textStatus,err=$errorThrow")
    },
    `type` = "GET"
).asInstanceOf[JQueryAjaxSettings])
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top