Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

onComplete and "response" parameter
  • Hey there,

    I'm developping an app using the last version (2.0.3) of uploadify, and first of all : it rocks. It really does.

    However, I have a little problem :

    The script I upload to send a response (...) in JSON using the PHP JSON_Encode() function.
    It works like a charm and outputs a nice :
    {\"status\":\"OK\", \"filename\":\"myfile.jpeg\", \"username\":\"foofoofoo\"}


    But, in my onComplete function, when I try to use this response as a jQuery object, it simply does not work because the string "Array" is prepended to the my response string itself. So I have, using alert(response) :

    Array{\"status\":\"OK\", \"filename\":\"myfile.jpeg\", \"username\":\"foofoofoo\"}


    I have to substring my response so that I can use my JSON string correctly. Is this done on purpose or something the flash does (and shouldn't do).

    response = response.substring(5);


    Thanks for any reply !
  • the only processing done to the data returned from the upload script is it is escaped before passing to javascript and unescaped before you get it. So it should have any affect.

    Still worth looking into though.

    Side thought: Are you JSON decoding before you do any processing?
  • Hey there,

    I'm not JSON decoding anything since jQuery actually does it all thanks to its magic.

    Browsing through the jQuery documentation, it clearly appears that doing $(test).... with test being a JSON string automatically makes it an object I can use. And removing the "Array" before passing the string to jQuery prooves this works.

    The "Array" appears when I alert(response) in the onComplete. I really wonder why this "Array" appears, since my response is a string (JSON).
  • I'm having a similar issue. Though I'm not getting an Array, I'm getting a literal string.

    my server-side code returns a correctly formated JSON string:
    {\"Success\" : true, \"Message\" : 'Error processing file.'}


    My javascript function for the onCompelte method is passed this string:
    \"{\"Success\" : true, \"Message\" : 'Error processing file.'}\"


    I've tried different Content-Types, all give the same response. i'm using the same method to return a JSON object fromteh server as I do in other pages, all work fine, so either the .swf file or the uploadify.js file is convertig my JSON object into a string.

    Ideally, I should be passed the object as it's returned from the server, otherwise I'd have to write a special-case scenario to properly handle the string.

    So I'm either doing something incorrectly, or the Uploadify plugin is doing this by design (I just haven't figured out how to convert the string into an object).

    thoughts? hints? help? know a good shrink? :)
  • I have a similar issue.

    The response I get back from the server is a proper JSON object:

    {\"Success\":false, \"Message\":'error message'}


    However, once I get to my custom onComplete function, it has been coverted into a string:

    \"{\"Success\":false, \"Message\":'error message'}\"

    This is obvioulsy not correct syntax for a string, but this is when I get.

    I am using C#.NET on the ServerSide, and have altered the method of how I return my values several times (content-type, encoding, format, etc), but I always get the same response.

    I am using the same method I use for all the other jQuery plugins throughout my site. This is the only one altering my output like this.

    so I either:
    1) request to know the proper method to return data to the onComplete to be able to use the object notation (response.Success, etc),
    2) be informed of how to convert the string back into a object literal (without using 'eval' if possible)
    or 3) Request a bug fix (or feature?) to have the uploadify functions return the same type data passed into it returned to customer functions (object literal. string).

    Help would be appriciated.
  • Hi!

    I had the same problem and the following onComplete handler solved it:

    onComplete: function(event, ID, fileObj, response, data){
    var data = $.parseJSON(response);
    if (data.type == 'notification') {
    alert('Do something');
    }
    },