dongzhan9100 2012-05-06 08:39
浏览 781
已采纳

发生错误:SyntaxError:JSON.parse:意外字符

I'm trying to update a record with JQuery/JSON but I'm seeing this error:

An error has occurred:

[object Object]

parsererror

SyntaxError: JSON.parse: unexpected character

My 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:
' + x + '
' + y + '
' + z);
    }
})

return false;
})

And my 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;

If my php is :

$ret = array(
    'error'             =>  'OK',
);
echo json_encode($ret);
exit;

then it works...

Tks for you help!

  • 写回答

2条回答 默认 最新

  • dr897777 2012-05-06 08:59
    关注

    Probably your PHP throws some Errors or Warnings, which make the returned document not a valid JSON string. Use a debugger like FireBug to see, what actual result is returned by your PHP script.

    Following the PHP docu for mysql_real_escape_string (link)it will throw an Error, if there is no active MySQL connection available. Maybe that's your problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#服务器#的问题:在VMware虚拟机中有一个域控服务器,克隆这个服务器后,使用克隆在另外一台服务器VMware虚拟机上打开,修改IP地址, 原域控服务器关闭
  • ¥150 计算DC/DC变换器平均模型中的参数mu
  • ¥25 C语言代码,大家帮帮我
  • ¥15 请问以下文字内容及对应编码是用了什么加密算法或压缩算法呢?
  • ¥15 无法使用此凭据登录,因为你的域不可用,如何解决?(标签-Windows)
  • ¥15 yolov9的训练时间
  • ¥15 二叉树遍历没有报错但无法正常运行
  • ¥15 在linux系统下vscode运行robocup3d上场球员报错
  • ¥15 Python语言实验
  • ¥15 SAP HANA SQL 增加合计行