admin管理员组文章数量:1414605
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
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 4Uncaught SyntaxError: Unexpected identifier
- 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
2 Answers
Reset to default 4Try 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);
本文标签: javascriptplupload json responseStack Overflow
版权声明:本文标题:javascript - plupload json response - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745170883a2645965.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论