Response.ContentType = "application/json"; 这个表示你的响应内容是 json 格式。
报错说明你认为name:'newName' 是json格式的想法是错的。你自己再试试。

解决方案 »

  1.   

    我改成Response.Write("{name: 'newName'}");了,为什么页面还是执行了error的代码呢?
      

  2.   

    那你就写成标准的json 试试。
    {"name":"zhangsan"}
      

  3.   

    现在我的ajax代码是这样的:$.ajax({ 
                        type: "post",
                        url: "login.aspx?action=add", 
                        data: $("#loginForm").serialize(),
                        contenttype: "application/json",
                        dataType: "json",
                        success: function (data) {
                            alert(data);
                        },
                        error: function (err) {
                            alert('出错了');
                        }
                    }); 后台代码是这样的:
    if (Request["action"] == "add")
                {                string bbb = Request["usercode"];
                    string ccc = Request["password"];
                    Response.ContentType = "application/json";
                    Response.Write("{'name':'zhangsan'}");
                    Response.End();
                    
                }还是执行了error的代码,求助啊!!!!
      

  4.   

    json 格式。错误
    改成 "{\"name\":\"zhangsan\"}"