【发布时间】:2016-10-12 09:01:32
【问题描述】:
我按照书 web development with clojure, 2nd edition 的示例代码进行操作,但在使用 google 关闭的情况下上传文件时遇到问题。
我用 Swagger 测试文件上传,它响应我 200 ok,我认为错误来自 upload-file! 函数。(见下文)。
但我查了closure api doc,似乎我使用了正确的功能。
所以我遇到了麻烦,我不知道为什么它不起作用......
我需要帮助。这是我的代码(我对 ui 组件使用语义 ui):
(defn upload-file! [upload-form-id status]
(reset! status nil)
(let [io (IframeIo.)]
(gev/listen
io goog.net.EventType.SUCCESS
#(reset! status [c/success-message "file uploaded successfully"]))
(gev/listen
io goog.net.EventType.ERROR
#(reset! status [c/warning-message "failed to upload the file"]))
(.setErrorChecker io #(= "error" (.getResponseText io)))
(.sendFromForm io (.getElementById js/document upload-form-id) "/upload")))
(defn upload-form []
(let [status (atom nil)
form-id "upload-form"]
(fn []
[c/modal
[:div "Upload File"]
[:div
(when @status @status)
[:div.ui.form
{:id form-id
:enc-type "multipart/form-data"
:method "POST"}
[:label {:for "file"} "select an image for upload"]
[:input {:id "file"
:name "file"
:type "file"}]]]
[:div
[:button.ui.primary.button
{:on-click #(upload-file! form-id status)}
"upload"]
[:button.ui.red.button
{:on-click #(do
(.modal (js/$ ".ui.modal") "hide")
(reset! status nil))}
"Cancel"]]
"upload"])))
组件:
(defn modal [header content footer id]
[:div.ui.modal
{:id id}
[:div.header header]
[:div.content content]
[:div.actions footer]])
(defn success-message [content]
[:div.ui.green.message
[:div.header content]])
【问题讨论】:
-
这是我的错误....我找到了,我应该输入 :form.ui.form,而不是 :div.ui.form。抱歉这个问题..
-
您可以回答自己的问题并将其标记为已解决:stackoverflow.com/help/self-answer
-
谢谢@n2o的提醒,我会回复的^_^,一开始我以为只是写错,不用回复。但你说得对,我应该标记为解决了。
-
您甚至可以将自己的答案标记为正确答案;-)
标签: clojure clojurescript google-closure-compiler luminus