I am trying to send JSON object but in result it is sending a parse error .
{"readyState":4,"responseText":"","status":200,"statusText":"OK"}
here is code
var data = {
fb_id: response.id,
email: response.email,
name: response.name,
first_name: response.first_name,
last_name: response.last_name,
verified: response.verified,
birthday:response.birthday,
picture: response.picture.data.url,
hometown: response.hometown.name,
gender: response.gender
};
$.ajax({
url:'connect.php',
type: 'POST',
data: {
user: data
},
dataType: 'JSON',
success: function(html){
//page();
console.log(JSON.stringify(data));
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
if (XMLHttpRequest.readyState == 4) {
console.log(JSON.stringify(XMLHttpRequest));
}
}
});
and the backend is here: The JSON object is sending here
if(isset($_POST['user'])) {
//convert json object to php associative array
$data = $_POST['user'];
$fbid = $data['fb_id']; // To Get Facebook ID
$fbfullname = $data['name']; // To Get Facebook full name
$femail = $data['email']; // To Get Facebook email ID
$fbname = $data['first_name'];
$fblname = $data['last_name'];
$fbgender = $data['gender'];
$fverified = $data['verified'];
$faddress = $data['hometown'];
$fbirth = $data['birthday'];
$img = $data['picture'];
}
The object is sending something like that:
{
"fb_id":"xxxxxxxxxxx99",
"email":"sxxxxxx@xxx.in",
"name":"Sagar xxxx",
...
}
PS: I am using 1.12.4 version of jquery.min.js
Updated When I tries to send request using this query to connect.php page it returns error in console log. and If i change dataType to "text" or exclude it then it doesn't return any error but then connect.php cannot identify any query posted using ajax request ,i.e., isset($_POST['user']) will not be able to identify any query .