0

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"}
Paolo Broccardo
  • 1,942
  • 6
  • 34
  • 51

2 Answers2

4

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.

Uriah Carpenter
  • 6,656
  • 32
  • 28
JNo
  • 395
  • 1
  • 4
  • Thanks. You are correct. While the JSON object can be any JSON object, it has to have that name/value pair of "success":"true" as you indicated for the functionality to work properly, even though that name/value pair is NOT required to have valid JSON. – Paolo Broccardo Mar 19 '13 at 17:53
  • @Leigh - I reverted the text back because the tool being used is actually called "Fine Uploader" (not File). I tried to enter that as a comment on the rollback but didn't see how. – Miguel-F Mar 19 '13 at 18:06
  • @Miguel-F - Oops, you are right! (The brain sees what it expects to see ;-) Thanks for the fix. – Leigh Mar 19 '13 at 18:13
1

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>
Miguel-F
  • 13,450
  • 6
  • 38
  • 63
  • Thanks, I have tried that, but just to be sure I tried it again. Same error. This is the code: ` #serializeJSON( sData )#` – Paolo Broccardo Mar 18 '13 at 19:28
  • That code works fine for me. Are you getting any errors? Remember, ColdFusion will prefix the JSON output with `//` by default. – Miguel-F Mar 18 '13 at 19:36
  • No errors, which is very strange. Just the Red dialog that says "Upload failed", as well as the alert that I put in that says "error". Other than that, there is no error anywhere in Firebug. The response returned is: `{"name":"Peter"}` – Paolo Broccardo Mar 18 '13 at 19:41
  • Okay, so that JSON output is correct. Does your "reason" variable contain anything useful? – Miguel-F Mar 18 '13 at 19:49
  • `Reason unknown` Helpful, I know. – Paolo Broccardo Mar 18 '13 at 20:07