javascript - plupload json response - Stack Overflow

I can't seem to make the response a json object.the ajax function (url parameter to plupload) echo

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

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

Share Improve this question edited Nov 28, 2011 at 16:25 Pointy 414k62 gold badges595 silver badges629 bronze badges asked Nov 28, 2011 at 16:17 AlexAlex 66.2k185 gold badges460 silver badges651 bronze badges 4
  • can you post the json string? Are you sure "response" contains it? – rob Commented Nov 28, 2011 at 16:22
  • 2 ok, the problem was the function parameter, which is actually a object and response is a property :| like response.response – Alex Commented Nov 28, 2011 at 16:23
  • Is "pluload" in the question title supposed to be "upload"? – Pointy Commented Nov 28, 2011 at 16:23
  • no, it's the plupload script... – Alex Commented Nov 28, 2011 at 16:24
Add a ment  | 

2 Answers 2

Reset to default 4

Try to use jQuery parseJSON method.

var json = $.parseJSON(response);

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);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745170884a4614916.html

相关推荐

  • javascript - plupload json response - Stack Overflow

    I can't seem to make the response a json object.the ajax function (url parameter to plupload) echo

    16小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信