问题
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
回答1:
Try to use jQuery parseJSON
method.
var json = $.parseJSON(response);
回答2:
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);
来源:https://stackoverflow.com/questions/8298793/plupload-json-response