re-frame

https://github.com/Day8/re-frame/blob/master/docs/README.md https://github.com/Day8/re-frame/blob/master/docs/External-Resources.md
bastilla 2020-10-04T09:54:34.033600Z

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]}})))

✅ 1
bastilla 2020-10-04T09:57:27.035200Z

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

✅ 1
p-himik 2020-10-04T10:02:14.035300Z

Provide either some :body or some :format.

p-himik 2020-10-04T10:03:06.035500Z

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))

bastilla 2020-10-04T10:05:34.035700Z

@p-himik Hey! Thanks. I'll have a look into it... Merci!

bastilla 2020-10-04T10:11:15.035900Z

Hey @p-himik 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!

bastilla 2020-10-04T10:33:09.036100Z

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

bastilla 2020-10-04T10:33:49.036300Z

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