Skip to content

Instantly share code, notes, and snippets.

@Will-Sommers
Created March 20, 2014 16:15
Show Gist options
  • Save Will-Sommers/9667532 to your computer and use it in GitHub Desktop.
Save Will-Sommers/9667532 to your computer and use it in GitHub Desktop.

Server response

(defn generate-response [data & [status]]
  {:status (or status 200)
   :headers {"Content-Type" "application/edn"}
   :body (pr-str {:1 "hi"})})
   

CLJS

(defn GETS [url]
  (let [ch (chan 1)]
    (xhr/send url
              (fn [event]
                (let [res (-> event .-target .getResponseText)]
                  (go (>! ch res)
                      (close! ch)))))
    ch))


(defn log [s]
  (println (reader/read-string (:1 s))))


(go
  (log (<! (GETS "http://127.0.0.1:8080/line/B/station/BST"))))

Error:

Uncaught TypeError: Cannot read property '0' of null reader.cljs:329
read_keyword reader.cljs:329
read_delimited_list reader.cljs:239
read_map reader.cljs:282
read reader.cljs:424
read_string reader.cljs:435
xx /Users/wls/code/cljs/om-tube-tracker/src/cljs/core.cljs[eval348]:107
cljs.core.async.impl.dispatch.run.call.switch__14921__auto__ /Users/wls/code/cljs/om-tube-tracker/src/cljs/core.cljs[eval353]:109
(anonymous function) /Users/wls/code/cljs/om-tube-tracker/src/cljs/core.cljs[eval353]:126
cljs.core.async.impl.dispatch.run.call.state_machine__14922__auto____1 /Users/wls/code/cljs/om-tube-tracker/src/cljs/core.cljs[eval353]:146
cljs.core.async.impl.dispatch.run.call.state_machine__14922__auto__ /Users/wls/code/cljs/om-tube-tracker/src/cljs/core.cljs[eval353]:163
run_state_machine ioc_helpers.cljs:34
run_state_machine_wrapped ioc_helpers.cljs:38
(anonymous function) ioc_helpers.cljs:47
(anonymous function) channels.cljs:42
process_messages dispatch.cljs:19
cljs.core.async.impl.dispatch.message_channel.port1.onmessage dispatch.cljs:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment