Implementing an ajax call in clojurescript

后端 未结 3 1543
广开言路
广开言路 2021-02-05 10:03

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 implem

3条回答
  •  北荒
    北荒 (楼主)
    2021-02-05 10:27

    The way I did it is slightly different. I don't know why the way that Marc suggested in his answer didn't work for me. Hopefully this is also useful.

    I used goog.net.XhrIo directly, rather than the xhr-connection wrapper.

    (defn callback [reply]
        (let [v (js->clj (.getResponseJson (.-target reply)))] ;v is a Clojure data structure
            (your-function-here v)))
    
    (.send goog.net.XhrIo url callback)
    

    The main difference that I can see is that I've used .-target to get the property of the JSON object, rather than calling target.

    It's worth noting that maps in v that have been created from JSON objects are keyed by strings not keywords.

提交回复
热议问题