FineUploader responseJSON doesnt contain success in onComplete callback

萝らか妹 提交于 2020-01-07 05:35:07

问题


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.

Client Side Code

    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

EDIT: 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.


回答1:


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)


来源:https://stackoverflow.com/questions/15528306/fineuploader-responsejson-doesnt-contain-success-in-oncomplete-callback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!