plupload json response

跟風遠走 提交于 2019-12-01 22:06:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!