错误描述:JSON parse error: Unrecognized token ‘username’: was expecting (‘true’, ‘false’ or ‘null’)
json输入格式错误。
//ajax发送请求
$.ajax({
url:"user/testAjax",
contentType:"application/json;charset = UTF-8"
data:{"username":"hh","password":"123","age":18},
dataType:"json",
type:"post",
success:function (data) {
alert(data);
alert(data.username);
}
解决方法:
将data行换成data:JSON.stringify({“username”:“hh”,“password”:“123”,“age”:18})