Handle responses with `ajax-request`
masterUnlike the high-level GET/POST APIs, ajax-request uses a single :handler function to manage both successful responses and errors. The handler must be a function that accepts a single vector argument in the form [ok result].
- If
okistrue,resultcontains the successful response data. - If
okisfalse,resultcontains the error response data.
(defn handler [[ok response]]
(if ok
(println "Success:" response)
(println "Error:" response)))
(ajax-request {:uri "/api" :method :get :handler handler})