Alex
Alex

Reputation: 68406

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

Upvotes: 3

Views: 5803

Answers (2)

Bird87 ZA
Bird87 ZA

Reputation: 2160

As of v3.0 of jQuery, $.parseJSON(response) has been deprecated.

From the docs:

As of jQuery 3.0, $.parseJSON is deprecated. To parse JSON strings use the native JSON.parse method instead.

The answer to above question is thus:

var json = JSON.parse(response);

Upvotes: 0

ShankarSangoli
ShankarSangoli

Reputation: 69905

Try to use jQuery parseJSON method.

var json = $.parseJSON(response);

Upvotes: 4

Related Questions