问题描述
我是新来的clojurescript,并希望通过实施previously书面申请纯粹clojurescript做了深入介绍,而是很茫然对于实现Ajax调用。任何人都可以点我一个例子在线或提供给我一个code段还是两个?
I'm new to clojurescript and would like to do a deeper dive by implementing a previously written application purely in clojurescript, but am at a loss with respect to to implement an ajax call. Can anyone point me to an example online or provide me with a code snippet or two?
推荐答案
好了,因为Clojurescript利用谷歌的关闭JavaScript库,快速搜索的封闭文档产生xhrIo的适当方法产生AJAX调用:
Okay, So given that Clojurescript leverages Google's Closure JavaScript library, a quick search of the Closure Documentation yielded xhrIo as the proper method for generating AJAX calls:
Example using Closure's Asynchronous XMLHttpRequests with XhrIo
goog.net.XhrIo.send(url, opt_callback, opt_method, opt_content,
opt_headers, opt_timeoutInterval)
在Clojurescript源的快速审查揭示了以下功能:
A quick review of the Clojurescript source revealed the following function:
从SRC / cljs / Clojure中/浏览器/ net.cljs在Clojure的/ clojurescript
(defn xhr-connection
"Returns an XhrIo connection"
[]
(goog.net.XhrIo.))
于是沿着这行的东西应该有预期的结果:
So something along the lines of this should have the intended results:
(def xhr xhr-connection)
(defn myCallback [replyValue]
... Do Something with replyValue
... for example: (someJsonFunc (.getResponseJson (.target replyValue))))
(defn ajax-json [url]
(.send xhr url myCallback))
有关JSONP,你可以使用goog.net.Jsonp类似的东西。请参阅以下链接了解详细信息:
For JSONP, you can do something similar using the goog.net.Jsonp. See the link for details:
希望有人认为这很有帮助!
Hope someone finds this helpful!
这篇关于实施clojurescript一个Ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!