我硬编码了
id
和 token
的值,这些值在这些 console.log
中返回,以便用 cljs-ajax
进行测试。它按预期与 AJAX 一起工作,但不是通过 re-frame-http-fx
.
(rf/reg-event-fx
::http-inicial
(fn [{:keys [db]} _]
(let [url (str (-> js/window .-location .-href))
id (second (str/split url #"#"))
token (:auth db)
log-id (js/console.log "id" id)
log-token (js/console.log "token" token)
endpoint1 (endpoint "PrestacoesDeContas" id)]
{:http-xhrio {:method :get
:uri endpoint1
:timeout 8000
:response-format (ajax/json-response-format {:keywords? true})
:headers (auth-header token)
:on-success [::success-pc-result]
:on-failure [::bad-http-result]}})))
退货:
shadow-cljs - remote-error Event {isTrusted: true, type: 'error', target: WebSocket, currentTarget: WebSocket, eventPhase: 2, …}
同时,这个 AJAX 调用正常返回数据。
(js/console.log
(let [token "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJub21lIjoiQ29vcmQgUFBJIiwiZW1haWwiOiJsdWNhcy5hbG1laWRhK2Nvb3JkcHBpMUBmYWN0aS5jb20uYnIiLCJncnVwb3MiOlsiVXN1w6FyaW8gZGUgQ29vcmRlbmFkb3JhIiwiUmVwcmVzZW50YW50ZSBMZWdhbCJdLCJfaWQiOiI2MTQ0OGEwMTVlOWQ2NjI4N2NkMzAzZWQiLCJpcCI6Ijo6MSIsImlkRW50aWRhZGUiOiI2MTc4MTRiOGU2MTU4NDVjNWNiMDIwNWMiLCJjbnBqRW50aWRhZGUiOiI1MDE2MzEzNDAwMDEwMCIsInBwaXMiOlt7Il9pZCI6IjYxY2IzMDdhZjQwOWUzNTEyODdhZWU4MCIsIm5vbWUiOiJQcm9ncmFtYSAyMDIyIn1dLCJpYXQiOjE2ODM4MTM3NTksImV4cCI6MTY4Mzg1Njk1OX0.dQhfvw-IEMom29sZzD5f6ro5Ly_vv6CKHHtvBszV2sQ"]
(ajax/GET (endpoint "PrestacoesDeContas" "645ce2d20bbd97cdbbce1602")
{:headers (auth-header token)
:handler #(js/console.log "handler" %)
:error-handler #(js/console.log "error-handler" %)})))
我做错了什么?我很确定它与终点无关,尽管错误消息会暗示这一点。
(
on-success
和on-failure
都是控制台日志,所以不用担心)。