FineUploader responseJSON在onComplete回调中不包含成功 [英] FineUploader responseJSON doesnt contain success in onComplete callback

查看:1524
本文介绍了FineUploader responseJSON在onComplete回调中不包含成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

获得onComplete方法后,我发现我的responseJSON变量似乎不包含我预期的信息。这是我在某个地方(可能),或不正常工作的东西吗? FineUploader正在识别一个成功的上传,所以我知道它得到的响应,但当我记录responseJSON在onComplete,它打印responseJSON:。只是文件名。无括号,括号等。

After getting the onComplete method to fire, I found that my responseJSON variable does not appear to contain the information I expected it to. Is this me screwing up somewhere(probably), or something not working quite right? FineUploader is recognizing a successful upload, so I know its getting the response, but when I log responseJSON in the onComplete, it prints "responseJSON: ". Just the file name. no braces, brackets, etc.

客户端代码

    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

服务器端响应代码(只是必要的部分)

Server side Response Code (just the necessary part)

response = 
    "success": true
    "discussionId": discussion.id
console.log JSON.stringify response
res.send JSON.stringify response

编辑:我还为FineUploader-3.3.0.js文件添加了一个日志,它接收到正确的JSON对象,它只是不传递它

I've also added a log to the FineUploader-3.3.0.js file, and it is receiving the correct JSON object, it is just not passing it back correctly for some reason.

推荐答案

onComplete方法的第一个参数实际上是事件,所以你真的引用 fileName responseJSON 。如果您更改方法参数以包含该事件,我认为应该可以正常工作。

The first parameter on the onComplete method is actually the event, so you're really referencing fileName with responseJSON. If you change your method parameters to include the event, I think that should work.

uploader.on "complete", (event, id, fileName, responseJSON)

这篇关于FineUploader responseJSON在onComplete回调中不包含成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆