我正在使用 Node.JS、Express 和 CoffeeScript 使用 FineUploader 创建我的第一个项目。到目前为止,一切都运行良好,只有一个例外。上传完成后,我将返回一个 JSON 对象,其中包含成功变量以及继续进行所需的另一个变量。不幸的是,我无法成功触发 onComplete 回调。我相信我的所有代码都是正确的,并且 Chrome 控制台没有抛出任何错误。我也尝试在 onComplete 方法中打印到 Chrome 控制台,但无济于事。任何帮助将不胜感激。
uploader = new $("#collaboration-fine-uploader").fineUploader
autoUpload: false
multiple: false
validation:
allowedExtensions: ['pdf', 'doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx']
sizeLimit: 1024*1024*1024*10 # 10MB
text:
uploadButton: "<i class='icon-plus icon-white'></i> Select Files"
request:
endpoint: "/files/discussions/collaborations/upload"
callbacks:
onComplete: (id, fileName, responseJSON) ->
if (responseJSON.success)
alert "response success"
discussionId = responseJSON.discussionId
$.ajax
type: "GET"
url: "/courses/"+serverData.course._id+"/discussions/"+discussionId
beforeSend: (xhr) ->
xhr.setRequestHeader 'x-pjax', 'true'
success: (html) ->
# Replace the old html
$(".discussions-tab").html html
$(".new-discussion").slideUp()
$("#new-discussion-modal").deactivateModal()
# History push
window.history.pushState window.history.state, "Discussions", "/courses/"+serverData.course._id+"/discussions/"+discussionId
# Scroll to top
$.scrollTo 0
$(".trigger-upload-and-submit").on "click", (e) ->
e.preventDefault()
uploader.fineUploader "setParams",
discussion:
title: $(".new-collaboration .discussion-title").val()
body: $(".new-collaboration .discussion-body").val()
groupId: serverData.course._id
showProfessors: $(".new-collaboration .show-professor-checkbox").attr("checked")
showStudents: $(".new-collaboration .show-students-checkbox").attr("checked")
type: "Collaboration"
uploader.fineUploader("uploadStoredFiles")