实施clojurescript一个Ajax调用clojurescript、Ajax

由网友(开着拖拉机去私奔)分享简介:我是新来的clojurescript,并希望通过实施previously书面申请纯粹clojurescript做了深入介绍,而是很茫然对于实现Ajax调用。任何人都可以点我一个例子在线或提供给我一个code段还是两个?I'm new to clojurescript and would like to do a de...

我是新来的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:

JSONP关闭API

希望有人认为这很有帮助!

Hope someone finds this helpful!

阅读全文

相关推荐

最新文章