Howdy, Stranger!

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

onComplete jSon decode (php)
  • Hello. What a wonderful app. thank you!

    I have a straightforward question. In my upload.php file I build an array, and then encode the array with json...
    $arr = array ('a'=>$var1,'b'=>$var2,'c'=>$var3,'d'=>$var4,'e'=>$var5);
    echo json_encode($arr);

    In my uploadify code, I want to call decode that array and replace a number of divs:
    'onComplete' : 
    function(event, queueID, fileObj, response, data) {
    $('div#one').html(/* the first decoded json var here /*);
    $('div#two').html(/* the second decoded json var here /*);
    $('div#three').html(/* the third decoded json var here /*);
    $('div#four').html(/* the forth decoded json var here /*);
    $('div#five').html(/* the fifth decoded json var here /*);
    }

    Could someone help me with decoding the response data? Thanks.
  • The easiest way is to use eval(). Although it is considered a security risk and a json parser should be used instead. There's some info at http://www.json.org/js.html

    'onComplete' : 
    function(event, queueID, fileObj, response, data) {
    eval(\"var obj1=\"+response);
    $('div#one').html(obj1.a);
    $('div#two').html(obj1.b);
    $('div#three').html(obj1.c);
    $('div#four').html(obj1.d);
    $('div#five').html(obj1.e);
    }