我正在关注《Web Development with Clojure, 3rd Edition 》一书中的代码示例。目前正在运行使用 ClojureScript 使用 Reagent 和 Ajax 创建单页应用程序的示例。编译的 Javascript 运行良好,直到我尝试将数据从表单发送到服务器。这应该是破解的,因为我没有在任何Ajax代码中添加一个csrf令牌到post请求,作者想介绍一下js控制台如何用于登录开发,但事实并非如此打破预期。我应该收到这样的东西:
error:{:status 403,
:status-text "Forbidden",
:failure :error,
:response "<h1>Invalid anti-forgery token</h1>"}
我已经确保我的所有依赖项和插件都是最新的。我最近切换到 Brave 进行测试,我非常喜欢它,但我遇到了一些这样的问题,当我在 Chrome 中测试它时,它运行正常(如预期的那样中断)。
这是我在 core.cljs 文件中的代码:
(:require [reagent.core :as r]
[ajax.core :refer [GET POST]]))
(defn send-message!
[fields]
(POST "/message"
{:params @fields
:handler #(.log js/console (str "response:" %))
:error-handler #(.log js/console (str "error:" %))}))
(defn message-form
[]
(let [fields (r/atom {})]
(fn []
[:div
[:div.field
[:label.label {:for :name} "Name"]
[:input.input
{:type :text
:name :name
:on-change #(swap! fields assoc :name (-> % .-target .-value))
:value (:name @fields)}]]
[:div.field
[:label.label {:for :message} "Message"]
[:textarea.textarea
{:name :message
:value (:message @fields)
:on-change #(swap! fields assoc :message (-> % .-target .-value))}]]
[:input.button.is-primary
{:type :submit
:on-click #(send-message! fields)
:value "Comment"}]
[:p "Name: " (:name @fields)]
[:p "Message: " (:message @fields)]])))
(defn home
[]
[:div.content
[:div.column.is-centered
[:div.column.is-two-thirds
[:div.columns
[:div.column
[message-form]]]]]])
(r/render [home] (.getElementById js/document "content"))
当我在 Brave 中打开页面时,我在加载时收到以下两条消息:
undefined
at log.js:38
Uncaught TypeError: goog.log.getLogger is not a function
at xhrio.js:249
(anonymous) @ xhrio.js:249
Javascript 仍然运行良好,但是当我点击“提交”按钮时,我收到这两个错误,我怀疑这可能是在 Google 的 Closure 代码中?没有把握:
at goog.net.XhrIo.ajax$protocols$AjaxImpl$_js_ajax_request$arity$3 (xhrio.cljs:30)
at ajax$protocols$_js_ajax_request (protocols.cljc:6)
at ajax$simple$raw_ajax_request (simple.cljc:64)
at ajax$simple$ajax_request (simple.cljc:67)
at ajax$easy$easy_ajax_request (easy.cljc:116)
at Function.cljs$core$IFn$_invoke$arity$variadic (core.cljc:75)
at ajax$core$POST (core.cljc:75)
at guestbook$core$send_message_BANG_ (core.cljs:7)
at core.cljs:30
at HTMLUnknownElement.callCallback (react-dom.inc.js:341)
(anonymous) @ xhrio.cljs:30
ajax$protocols$_js_ajax_request @ protocols.cljc:6
ajax$simple$raw_ajax_request @ simple.cljc:64
ajax$simple$ajax_request @ simple.cljc:67
ajax$easy$easy_ajax_request @ easy.cljc:116
(anonymous) @ core.cljc:75
ajax$core$POST @ core.cljc:75
guestbook$core$send_message_BANG_ @ core.cljs:7
(anonymous) @ core.cljs:30
callCallback @ react-dom.inc.js:341
invokeGuardedCallbackDev @ react-dom.inc.js:391
invokeGuardedCallback @ react-dom.inc.js:448
invokeGuardedCallbackAndCatchFirstError @ react-dom.inc.js:462
executeDispatch @ react-dom.inc.js:594
executeDispatchesInOrder @ react-dom.inc.js:616
executeDispatchesAndRelease @ react-dom.inc.js:719
executeDispatchesAndReleaseTopLevel @ react-dom.inc.js:727
forEachAccumulated @ react-dom.inc.js:701
runEventsInBatch @ react-dom.inc.js:744
runExtractedPluginEventsInBatch @ react-dom.inc.js:875
handleTopLevel @ react-dom.inc.js:6026
batchedEventUpdates @ react-dom.inc.js:2342
dispatchEventForPluginEventSystem @ react-dom.inc.js:6121
dispatchEvent @ react-dom.inc.js:6150
unstable_runWithPriority @ react.inc.js:2820
runWithPriority$2 @ react-dom.inc.js:11443
discreteUpdates$1 @ react-dom.inc.js:21810
discreteUpdates @ react-dom.inc.js:2357
dispatchDiscreteEvent @ react-dom.inc.js:6104
react-dom.inc.js:481
Uncaught TypeError: G__20367.setTimeoutInterval is not a function
at goog.net.XhrIo.ajax$protocols$AjaxImpl$_js_ajax_request$arity$3 (xhrio.cljs:30)
at ajax$protocols$_js_ajax_request (protocols.cljc:6)
at ajax$simple$raw_ajax_request (simple.cljc:64)
at ajax$simple$ajax_request (simple.cljc:67)
at ajax$easy$easy_ajax_request (easy.cljc:116)
at Function.cljs$core$IFn$_invoke$arity$variadic (core.cljc:75)
at ajax$core$POST (core.cljc:75)
at guestbook$core$send_message_BANG_ (core.cljs:7)
at core.cljs:30
at HTMLUnknownElement.callCallback (react-dom.inc.js:341)
(anonymous) @ xhrio.cljs:30
ajax$protocols$_js_ajax_request @ protocols.cljc:6
ajax$simple$raw_ajax_request @ simple.cljc:64
ajax$simple$ajax_request @ simple.cljc:67
ajax$easy$easy_ajax_request @ easy.cljc:116
(anonymous) @ core.cljc:75
ajax$core$POST @ core.cljc:75
guestbook$core$send_message_BANG_ @ core.cljs:7
(anonymous) @ core.cljs:30
callCallback @ react-dom.inc.js:341
invokeGuardedCallbackDev @ react-dom.inc.js:391
invokeGuardedCallback @ react-dom.inc.js:448
invokeGuardedCallbackAndCatchFirstError @ react-dom.inc.js:462
executeDispatch @ react-dom.inc.js:594
executeDispatchesInOrder @ react-dom.inc.js:616
executeDispatchesAndRelease @ react-dom.inc.js:719
executeDispatchesAndReleaseTopLevel @ react-dom.inc.js:727
forEachAccumulated @ react-dom.inc.js:701
runEventsInBatch @ react-dom.inc.js:744
runExtractedPluginEventsInBatch @ react-dom.inc.js:875
handleTopLevel @ react-dom.inc.js:6026
batchedEventUpdates @ react-dom.inc.js:2342
dispatchEventForPluginEventSystem @ react-dom.inc.js:6121
dispatchEvent @ react-dom.inc.js:6150
unstable_runWithPriority @ react.inc.js:2820
runWithPriority$2 @ react-dom.inc.js:11443
discreteUpdates$1 @ react-dom.inc.js:21810
discreteUpdates @ react-dom.inc.js:2357
dispatchDiscreteEvent @ react-dom.inc.js:6104
关于为什么它在 Chrome 中按预期运行但在 Brave 中没有的任何想法?