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]}})))
Maybe you see some grave errors from the code? Error message in browser console is Uncaught Error: ["unrecognized request format: " nil]
Provide either some :body
or some :format
.
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))
@p-himik Hey! Thanks. I'll have a look into it... Merci!
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!
Correction. Still wrong. THIS did the trick:`:params {:location location :draft draft}` :format (ajax/json-request-format)
:params {:location location :draft draft
:format (ajax/json-request-format)