我正在尝试使用 JQuery/JSON 更新记录,但我看到了这个错误:
发生了错误:
[对象对象]
解析器错误
SyntaxError: JSON.parse: 意外字符
我的 JS:
jQuery('#commentForm').live('submit', function (event) {
event.preventDefault()
jQuery.ajax(edit_url, {
data: jQuery(this).serialize(),
dataType: 'json',
type: 'POST',
success: function (data) {
if (data.error === 'OK') {
alert('ok c good')
} else {
alert('hi' + data.error)
}
},
error: function(x,y,z){
alert('An error has occurred:\n' + x + '\n' + y + '\n' + z);
}
})
return false;
})
还有我的 php:
$ret = array(
'error' => 'OK',
);
$update =
"UPDATE crm_set_users SET ".
"crm_set_users_civilite = '".mysql_real_escape_string($crm_set_users_civilite)."',".
"crm_set_users_nom = '".mysql_real_escape_string($crm_set_users_nom)."',".
"crm_set_users_prenom = '".mysql_real_escape_string($crm_set_users_prenom)."',".
"crm_set_users_email = '".mysql_real_escape_string($crm_set_users_email)."', ".
"crm_set_users_telephone = '".mysql_real_escape_string($crm_set_users_telephone)."', ".
"crm_set_users_portable = '".mysql_real_escape_string($crm_set_users_portable)."'";
if($crm_set_users_photo != ""){
$update .=", crm_set_users_photo = '".mysql_real_escape_string($crm_set_users_photo)."'";
}
$update .=
"WHERE ".
"crm_set_users_id = '".mysql_real_escape_string($user_id)."'";
echo json_encode($ret);
exit;
如果我的 php 是:
$ret = array(
'error' => 'OK',
);
echo json_encode($ret);
exit;
然后它工作......
谢谢你的帮助!