Fork me on GitHub
#re-frame
<
2020-10-04
>
bastilla09:10:34

hi there! I have a beginner's question regarding the use of cljs-ajax via :http-xhrio. How to send POST data? Scrabbled some docs but I still fail with this code: (rf/reg-event-fx ::save-draft (fn [coeffects event] (let [db (:db coeffects) location (get event 1) draft (a/get-draft-text db location)] {:db (assoc db :show-twirly true) :http-xhrio {:method :post :uri "/api/save-file" :params {:location location :draft draft} :timeout 8000 ; optional see API docs :response-format (ajax/json-response-format {:keywords? true}) :on-success [::draft-saved] :on-failure [::draft-not-saved]}})))

3
bastilla09:10:27

Maybe you see some grave errors from the code? Error message in browser console is Uncaught Error: ["unrecognized request format: " nil]

3
p-himik10:10:14

Provide either some :body or some :format.

p-himik10:10:06

I have these lines in my code:

;; With nil body, `cljs-ajax` cannot guess for us.
:format (when (nil? (:body params)) (ajax/url-request-format))

bastilla10:10:34

@U2FRKM4TW Hey! Thanks. I'll have a look into it... Merci!

bastilla10:10:15

Hey @U2FRKM4TW you rock! This did the trick: :body {:location location :draft draft} instead of :params {:location location :draft draft} Now I run into server trouble (400) but this a a different topic. 1000 Thanks!

bastilla10:10:09

Correction. Still wrong. THIS did the trick:`:params {:location location :draft draft}` :format (ajax/json-request-format)

bastilla10:10:49

:params {:location location :draft draft :format (ajax/json-request-format)