Cljs-ajax's response format

[ajax.core :as ajax :refer [GET POST PUT]]

(ajax/GET  "" )
;;=> #object[Object [object Object]]
>CLJS-AJAX response: {.......}

response start with “cljs-ajax response” , how can i convert it to clojurescript atom and assoc db in reagent?


The docs showed an example of getting data from the channel:

(go (let [response (<! (http/get ""
                                 {:with-credentials? false
                                  :query-params {"since" 135}}))]
      (prn (:status response))
      (prn (map :login (:body response)))))

So you need to use core.async in this.

I remembered cljs-http has a callback form, not found in docs, feeling strange.

如果需要中文可以在 贴一个.


I think the question is about the cljs-ajax library, not cljs-http. What you need to do is install a handler:

  {:handler (fn [response] (swap! my-atom :key response))
   :error-handler (fn [{:keys [status status-text]}] (do-something))})

Note, cljs-ajax plays nicely with the promesa library if you prefer using promises instead of core.async or atom-based callbacks. You just wrap the ajax call in a new promise and then call resolve and reject in the handler and error-handler. I find the error handling to be much more predictable with promises when making simple ajax calls.


Thank for correcting.