I am sending a JSON string (correctly recieved from the facebook api) to PHP using ajax. When I try and parse the JSON string it adds extra characters to the string and when I try and obtain a value from the string I get nothing.
Here is the json as returned from facebook:
{"id":"redacted","email":"redacted","first_name":"redacted","gender":"female","last_name":"redacted","link":"redacted","locale":"en_US","name":"redacted","timezone":-6,"updated_time":"2014-12-17T23:10:00+0000","verified":true}
Here is the ajax:
$.ajax({
type: "POST",
url: "signupfacebookajax.php",
data: { theresponse: JSON.stringify(response) },
success: function(crap){ console.log(crap)}
});
});
Here is the code on the php page signupfacebookajax.php:
$response = $_POST['theresponse'];
$jsondecode = json_decode($response);
$facebook_id = $jsondecode->id;
echo $facebook_id;
Noting is returned at all. While troubleshooting I noticed that the JSON string looks odd after decoding it. Here is what I get after decoding the string after passed by ajax.
{\"id\":\"redacted\",\"email\":\"redacted\",\"first_name\":\"redacted\",\"gender\":\"female\",\"last_name\":\"redacted\",\"link\":\"redacted\",\"locale\":\"en_US\",\"name\":\"redacted\",\"timezone\":-6,\"updated_time\":\"2014-12-17T23:10:00+0000\",\"verified\":true}
Have you tried disabling magic quotes??? It looks like your php.ini has
magic_quotes_gpc = On
for more read Disable Magic Quotes
To disable it just replace On with Off
magic_quotes_gpc = Off
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.