Fork me on GitHub

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})
      (db/create-user! params)
      (response/ok {:status :ok})
      (catch Exception e
{:errors {:server-error ["Failed to save user!"]}})))))

(defroutes home-routes
  (GET "/" []
  (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:
 (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]}}))


do you include a csrf anti forgery token?

👍 5

@UAL5YQV7S oh no I missed that! now I added csrf token and now I got different error which is http status 500. I think server now accepted request but there is some problem in request.. and I don't know how to fix still!


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.

👍 5

yeah I'm searching for the serverside code now. Anyway thank you for letting me go beyond 403 status code!