<script>
$.ajax({
url: 'ajax.php?act=personal',
type: 'post',
dataType: 'json',
data: { name:name, phone:$('#phone').val(), alipay:$('#alipay').val(), weixin:$('#weixin').val(), qq:$('#qq').val(), email:$('#email').val() },
success: function(data){
if(data.success){
toast_tip(保存成功);
} else {
toast_tip(保存失败);
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
},
</script>
});
php代码
if(isset($_GET['act'])){
switch ($_GET['act']) {
//保存资料////////////////////////////////////////////////
case 'personal':
try {
//修改数据
$stmt = $db->prepare('UPDATE members SET Name=:Name, Phone=:Phone, AliPay=:AliPay, WeiXin=:WeiXin, QQ=:QQ, EMail=:EMail WHERE UserName=:UserName') ;
$stmt->execute(array(':Name' => $name, ':Phone' => $phone, ':AliPay' => $alipay, ':WeiXin' => $weixin, ':QQ' => $qq, ':EMail' => $email, ':UserName' => $_SESSION['UserName'] ));
} catch(PDOException $e) {
$error[] = $e->getMessage();
}
echo '{"message":"保存成功","success":true}';
break;
}
}
修改数据能成功, 但是老是回调error
返回代码 200, 4, parsererror