Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
How to get status code of successful response in handler in cljs-ajax?

I am successfully getting a response from an endpoint using cljs-ajax (as shown below). However, I cannot seem to differentiate between different success status codes in my response handler.

(ns mynamespace
  (:require [ajax.core :as ajax]))

(defn start-monitoring []
  (let [handler (fn [[ok response]]
                  (if ok
                    (.log js/console response)
                    (.error js/console (str response))))]
    (ajax/ajax-request {:uri "/myendpoint"
                   :method :get
                   :params {:since (.getTime (js/Date.))}
                   :handler handler
                   :format (ajax/json-request-format)
                   :response-format (ajax/json-response-format {:keywords? true})})))

"ok" in the handler appears to simply be a true/false success flag, and does not differentiate between 200 and 204 status codes, both of which are considered successes. The response body is whatever text is returned in the response, and doesn't appear to contain a status code, unless the request failed.

How can I determine the status code of the response?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Seems like the response is a map with keys like :status which contains 200 for my test. The rest of the keys are: (:status :failure :response :status-text :original-text)

about 4 years ago · Santiago Trujillo Report

0

Use :response-format (ajax/ring-response-format). See also: https://github.com/JulianBirch/cljs-ajax/issues/57

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!