Through the ajax method, JSON data is returned after amateur logic processing in the background. What is obtained in the foreground is the Object type. I would like to ask what is going on.
ajax method:
$.ajax({
type:"post",
url:"user/ReturUser",
dataType:"json",
data:{"id":city},
success:function(data){
alert(data); //The output is Object:Object
});
Backstage:
@ResponseBody
@RequestMapping("/ReturUser")
public Object ReturUser(Model model){
userss=(Users)request.getSession().getAttribute("users");
System.out.println(JSON.toJSONString(userss)); //有值有输出
return JSON.toJSONString(userss);
}
My ability is limited, find someone to help solve my doubts
What is returned is an object
alert(data.balance)
Don’t alert directly, you still need to do json parsing
Of course your alert will be an object_(:з ∠)_, or you can convert it into a json string and alert again to see if the data is successfully obtained
You can just write like this in the background, and the front desk will get the User object directly
This is correct, you can use it directly, it is recommended to use
console.log(data)
to print; then you need to use a specific field to directly usedata.calls
to getMs. Chen
What was passed was an object.
You can debug using F12 of the browser, and then hit the breakpoint on that JS to see the value inside.