为什么一直报这个错 Uncaught SyntaxError: Unexpected token : in JSON at position 9
死活都没看出来到底哪里出问题,说我申明data的那一行有错误?
报错信息:
VM128:1 Uncaught SyntaxError: Unexpected token : in JSON at position 9
at JSON.parse (<anonymous>)
at XMLHttpRequest.request.onreadystatechange (demo.html:71)
代码:
document.getElementById("save").onclick =function(){
//发送查询请求并处理
var request = new XMLHttpRequest();//申明变量
request.open("POST","service.php");//创建请求,并且带上参数
var data="name="+document.getElementById("staffName").value
+"&number="+document.getElementById("staffNumber").value
+"&sex="+document.getElementById("staffSex").value
+"&job="+document.getElementById("staffJob").value;
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
request.send(data);//发送请求
request.onreadystatechange=function(){
if(request.readyState===4){
if(request.status===200){
var data=JSON.parse(request.responseText);
if(data.success){
document.getElementById("creatResult").innerHTML=data.msg;
}else{
document.getElementById("creatResult").innerHTML="出现错误:"+data.msg;
}
}else{
alert("发生错误:"+request.status);
}
}
}
}
上传的截图怎么那么渣呢!