[英]Ajax keeps sending null values to the method even tho facebook is giving me the requested data
我正在嘗試通過Facebook登錄,在控制台中它顯示我正在獲取所請求的數據(email,first_name ...)但是ajax繼續向PHP方法發送空數據。
這是ajax代碼:
function saveUserData() {
FB.api('/me?fields=id,first_name,last_name,email', function(response){
$.ajax({
url: '<?php echo base_url();?>Auth/fb_auth',
data: {response: JSON.stringify(response)},
type: 'POST',
dataType: 'json',
success: function (data) {
if(data['state'] == 'ok'){
window.location.href ="<?php echo base_url(); ?>";
}
}
});
});
}
這就是我在方法中獲取數據的方法:
$response = json_decode($this->input->post('response'), true);
您不需要使用$.ajax
對字符串進行字符串化,它會為您執行此操作。 此外,您可以使用$.post
代替:
function saveUserData() {
FB.api('/me?fields=id,first_name,last_name,email', function(response){
$.post({
url: '<?php echo base_url();?>Auth/fb_auth',
data: response,
dataType: 'json',
success: function (data) {
if(data['state'] === 'ok'){
window.location.href ="<?php echo base_url(); ?>";
}
}
});
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.