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);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745170884a4614916.html
评论列表(0条)