Paolo Broccardo
Paolo Broccardo

Reputation: 1744

FineUploader error after processing Coldfusion page

I have implemented the latest version of FineUploader and it renders perfectly on my page.

 $(document).ready(function () {
    $('#jquery-wrapped-fine-uploader').fineUploader({
      request: {
        endpoint: 'fu/fineuploader.cfm'
      }
    }).on('error', function(event, id, name, reason) {
        alert('error');
      })
      .on('complete', function(event, id, name, responseJSON){
        alert('complete');
      });
  });

I then select a file and it contacts contacts the Coldfusion page successfully. If I look in the debugger tools / console, I can see the Coldfusion page's response. If I CFDUMP the FORM data, I see the file being passed as well. So everything works up to now.

However, once the Coldfusion page is done, the calling page fires the 'error' function and alerts 'error'.

If I look in the debugger / console, there are no errors. So I can't understand why the control is still returning an error. I suspect the error might be what I am returning from the cfm page, which is currently (this is all that is written in the cfm page at the moment):

<cfoutput>#serializeJSON( 'true' )#</cfoutput>

Does anyone see anything wrong here? I really don't know where to look to try and resolve this as there are no errors.

I am using CF10, FineUploader 3.3, Chrome

Thanks in advance.

UPDATE / ADDENDUM TO ACCEPTED ANSWER:

Basically, not only does the response have to be JSON formatted correctly, but it must have the name/value pair of “success”:”true” .

So, before, the JSON I was returning was this, which is valid JSON, but failed:

{"name":"Peter"}

However, it only started working properly after the addition of the “success”:”true” name/pair:

{"success":"true","name":"Peter"}

Upvotes: 0

Views: 596

Answers (2)

JNo
JNo

Reputation: 395

On a successful upload, your JSON response must return the key "success" with a value of "true".:

{
  "success" : "true"
}

If Fine Uploader doesn't see the JSON key "success" with a value of "true", it assumes that the upload failed on the server-side. Additional JSON properties can also included in the response.

Upvotes: 4

Miguel-F
Miguel-F

Reputation: 13548

You need to specify a ColdFusion variable in your serializeJSON() call (the variable that you want to serialize). Also, by specifying 'true' as the second paramenter to the serializeJSON() function you are actually telling it to create WDDX output, not JSON. See the documentation for SerializeJSON here.

Your code should look something like:

<cfoutput>#serializeJSON(YourCFVariableHere)#</cfoutput>

Upvotes: 1

Related Questions