我想發送JSON對象,但結果它發送了一個解析錯誤。JSON解析錯誤響應「狀態」:200,「statusText」:「確定」
{"readyState":4,"responseText":"","status":200,"statusText":"OK"}
這裏是代碼
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));
}
}
});
和後端是在這裏: 的JSON對象在這裏發送
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'];
}
的對象發送類似的東西:
{
"fb_id":"xxxxxxxxxxx99",
"email":"[email protected]",
"name":"Sagar xxxx",
...
}
PS:我用1.12 .4版jquery.min.js
已更新 當我嘗試使用此查詢向connect.php頁發送請求時,它將在控制檯日誌中返回錯誤。如果我更改dataType爲「文本」或排除它,那麼它不會返回任何錯誤,但然後connect.php無法識別使用ajax請求發佈的任何查詢,即isset($ _ POST ['user'])將無法以識別任何查詢。
寫一些更多的關於哪一邊的錯誤是php或js? –
[此問題]的副本(http://stackoverflow.com/questions/6186770/ajax-request-return-200-ok-but-error-event-is-fired-instead-of-success) – Red