Search code examples
javascriptjqueryjsonplupload

plupload json response


I can't seem to make the response a json object.

the ajax function (url parameter to plupload) echoes the response like this:

echo json_encode(array(
  'foo'    => 3434,
  'error'  => 'omg error',
));

exit;

and in the FileUploaded event I'm evaluating that:

var json = eval('(' + response + ')');
console.log(json);  

But I get a error

Uncaught SyntaxError: Unexpected identifier


Solution

  • Try to use jQuery parseJSON method.

    var json = $.parseJSON(response);