0
我遵循書web development with clojure, 2nd edition的示例代碼,我有一個與谷歌關閉文件上傳的問題。cljs + luminus框架:文件上傳與谷歌關閉
我測試用揚鞭文件上傳,它響應了我200 OK,我認爲錯誤是從上傳文件!函數(見下文)。
但我擡頭看看closure api doc,看來我用的是正確的功能。
於是我就在一個麻煩,我不知道爲什麼它不工作...
我需要有人help.Here是我的代碼(我用語義的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 。對此問題的回答.. – g1eny0ung
您可以回答自己的問題並將其標記爲已解決:http://stackoverflow.com/help/self-answer – n2o
謝謝您的提醒@n2o,我會回答^ _ ^,起初我認爲這只是一個寫錯誤,並不需要回答。但是你是對的,我應該把它標記爲已解決。 – g1eny0ung