I working on google sign in with JavaScript , if user signed in with google I will get his basic information as json data and send this data to php script , this script will insert user into my sql database but I don't know how can I retrieve json data which is sending by jquery in php this is my jquery code
function update_user_data(response)
{
var dataString = JSON.stringify(response);
alert(dataString);
$.ajax({
type: "POST",
dataType: 'json',
data: {myData:response},
url: 'Save.php?id=check_user',
success: function(msg) {var msgs=JSON.stringify(msg);
alert(msg);
// var array = msg.split(',');
// var email =array[0];alert(email);
//var password = array[1];alert(password);
//$('#username').val(email);$('#password').val(password);
// document.getElementById("modal4c").click();
},
error: function(msg) {alert(JSON.stringify(msg));
alert(msg);
}
});
}
you can see that I send the json string to Save.php?id=check_user
here is th save.php code
$obj = $_POST['myData'];
echo $obj['id'];
the json data which I send by javascript is like this
"{\"kind\":\"plus#person\",\"etag\":\"\\\"EhMivDE25UywestNG8tqFM2v-
A/ExECAGokGQl1532fQP_aRYY\\\"\",\"gender\":\"male\",\"emails\":
\"objectType\":\
"person\",\"id\":\"23229164823262432640\",\"displayName\":\"mohamad
buvaydanı\",\"name\":{\"familyName\":\"buvaydanı\",\"givenName\":\"mohadmad\"},\"url\":\"https://plus.google.com/1128891s326438205624449640\",\"image\"
}
but the php script reply with "{" message only
There is not id
in your data. you passing data: {myData:response},
only. your data should be like data: {id:123, myData:response},
and you have to decode it first in php file because it is json format, not array. json_decode($_POST, true);
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.