jquery.ajax post总提示语法错误,无效字符串
var str1="{Name:'张三',Sex:'男',Birthday:'1999-09-09',Married:'已婚'}" ; // userobj=JSON.parse(str1); --这一行 运行不了 已引用了json2.js jQuery.ajax({ type: "POST", contentType: "application/json;utf-8", url: "hrStaffReg.do", data: str1, //---->这个位置老提示出现语法错误 dataType: "json", success: function(data) { alert("ok"); }, error: function(xhr,txtStatus,errThrow) { alert("error:\n " + errThrow); } });
data: str1, //---->这个位置老提示出现语法错误
data这里提交的数据有2种方法,
var str1="{Name:'张三',Sex:'男',Birthday:'1999-09-09',Married:'已婚'}" ;
1: data:"name=张三&sex=男&birthday=1999-09-09&Married=已婚";
2: data:{Name:'张三',Sex:'男',Birthday:'1999-09-09',Married:'已婚'};
你自己试一下. 毕业论文
jQuery.ajax({
type: "POST",
contentType: "application/json;utf-8",
url: "hrStaffReg.do",
data: {'Name':'张三','Sex':'男','Birthday':'1999-09-09','Married':'已婚'}, //---->这个位置老提示出现语法错误
dataType: "json",
success: function(data) {
alert("ok");
},
error: function(xhr,txtStatus,errThrow) {
alert("error:\n " + errThrow);
}
});
问题找到了,不是客户端脚本的问题,而是servlet 端出了问题