Skip to content

Commit

Permalink
Set up fetch POST/CSRF test in example. #28
Browse files Browse the repository at this point in the history
  • Loading branch information
chr15m committed Feb 13, 2024
1 parent ff1a762 commit c912a9e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion examples/form-validation/webserver.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@
(when (aget ve "count")
[:p.warning (aget ve "count" "message")])
[:p [:input {:name "_csrf" :type "hidden" :default-value csrf-token}]]
[:button {:type "submit"} "Submit"]]]))
[:button {:type "submit"} "Submit"]]
[:h3 "Fetch POST test"]
[:div#ajaxresult]
[:button#ajax "Send fetch request"]
[:script {:dangerouslySetInnerHTML
{:__html
"ajax.onclick=()=>{fetch('/ajax',{'method':'POST','data':'hello','headers':{'Content-Type':'text/plain'}})
.then(r=>r.text()).then(d=>{ajaxresult.innerHTML=d})}"}}]]))

(defn view:thank-you []
[:div
Expand Down Expand Up @@ -83,6 +90,7 @@
(web/reset-routes app)
(web/static-folder app "/css" "node_modules/minimal-stylesheet/")
(.use app handle-csrf-error)
(.post app "/ajax" (fn [req res] (.send res (aget req "body"))))
(.use app "/" serve-form))

(defonce serve
Expand Down

0 comments on commit c912a9e

Please sign in to comment.