hello all! I'm having problem using ajax from re-frame clientside to serverside. I used provided template which luminus auto-created and changed a little. The thing is when I send the POST request from clientside, I only get HTTP 403 status code from network panel. 403 code means that somehow serverside rejected the request, so I guess the problem exists in the serverside code.(it might be not) I've been trying to fix the serverside code but I have no idea where to start since it's first time trying to use ajax.. Can anybody help? I'm putting the serverside code below (routes/home.clj):
(defn save-user! [{:keys [params]}]
(if-let [errors (validate-message params)]
(response/bad-request {:errors errors})
(try
(db/create-user! params)
(response/ok {:status :ok})
(catch Exception e
(response/internal-server-error
{:errors {:server-error ["Failed to save user!"]}})))))
(defroutes home-routes
(GET "/" []
(home-page))
(POST "/user" req (save-user! req)))
my question is,
Do I have to do something more in the serverside? or Is there a problem in the current code? or Can it even be clientside problem?
Here's the cljs request code:
(rf/reg-event-fx
:send-name
(fn [{:keys [db]} [_ user]]
{:db (assoc db :loading? true)
:http-xhrio {:method :post
:uri "/user"
:params user
:timeout 5000
:format (ajax/json-request-format)
:response-format (ajax/json-response-format {:keyword? true})
:on-success [:add-name]}}))
That sounds like an exception thrown in the server side code. could be its not receiving the params it expects from the request, or just an unrelated bug.
1👍yeah I'm searching for the serverside code now. Anyway thank you for letting me go beyond 403 status code!
do you include a csrf anti forgery token?
1👍