在触发onComplete方法之后,我发现我的responseJSON变量似乎不包含我期望它的信息。这是我搞砸了某个地方(可能),还是一些行不通的东西? FineUploader正在识别成功上传,所以我知道它获得了响应,但是当我在onComplete中记录responseJSON时,它会输出“responseJSON:”。只是文件名。没有大括号,括号等。
客户端代码
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"
uploader.on "complete", (id, fileName, responseJSON) ->
console.log "responseJSON: "+responseJSON
if (responseJSON.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
服务器端响应代码(只是必要部分)
response =
"success": true
"discussionId": discussion.id
console.log JSON.stringify response
res.send JSON.stringify response
编辑:我还在FineUploader-3.3.0.js文件中添加了一个日志,它正在接收正确的JSON对象,但由于某种原因它没有正确传回。
答案 0 :(得分:1)
onComplete方法的第一个参数实际上就是事件,因此您实际上是使用fileName
引用responseJSON
。如果您更改方法参数以包含事件,我认为这应该有效。
uploader.on "complete", (event, id, fileName, responseJSON)