JSON says it's null?
My server side code: returns an array:
return array('success'=>true, 'client_id' => $_GET['id']);
which is then echo'd
echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);
JSON looks like this when outputting;
{"success":true,"client_id":"db7A8"}
But when I run
onComplete: function(id, fileName, responseJSON){
var newBucket = $.parseJSON(responseJSON);
al开发者_如何学Goert(newBucket.client_id);
}
it says that it's null (it's a function of AJAX upload), any idea what's wrong here?
Have you specified proper ContentType header while returning JSON data from php? IE and Chrome doesn't like to receive JSON under the wrong ContentType header.
If that doesn't solve your problem try using this http://code.google.com/p/jquery-json/
var encoded = $.toJSON(responseJSON);
var newBucket = $.evalJSON(encoded);
alert(newBucket.client_id);
Edit : the code above is using the mentioned jquery plugin to serialize the responseJSON before parsing it. You may use other alternative methods to do the same if you don't want to use that jquery plugin.
精彩评论