luminus

sis_xiphos 2019-02-09T14:50:55.074200Z

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

Ellie 2019-02-10T16:44:52.074800Z

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
sis_xiphos 2019-02-12T02:24:59.000300Z

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

Ellie 2019-02-09T16:34:43.074400Z

do you include a csrf anti forgery token?

👍 1