我有一个这样的 spring mvc Web 服务:
@Controller
@RequestMapping("/hello")
public class helloWs {
@RequestMapping(value= "/getObj", method = RequestMethod.GET)
public
@ResponseBody
User prueba(@RequestBody User user) {
user.setEmail("sample_email@sample.com");
user.setName("sample_name");
user.setDeleted(true);
return user;
}
}
对此 Web 服务的 jquery 调用位于一个包含以下函数的 html 文件中:
function hellowsfunction() {
$.ajax({
type: "GET",
url:"http://localhost:8080/ehCS-ui/rest/hello/getUser",
dataType: "jsonp",
success: function(msg) {
$('#lblResult').html('<p> Name: ' + msg.name + '</p>');
$('#lblResult').append('<p>email : ' + msg.email+ '</p>');
$('#lblResult').append('<p> deleted: ' + msg.setDeleted+ '</p>');
alert('Success: ' + response);
},
error: function (e) {
$("#lblResult").removeClass("loading");
alert('failed:'+e);
console.log(e);
}
});
}
结果应该在这样的 div 中。
<div id ="lblResult" style="color:blue;">result here</div>
Web服务还可以,但是Jquery似乎没有读取json obectj:这是Web服务在浏览器上返回的用户对象。
{"version":null,"deleted":true,"insertDate":null,"updateDate":null,"owner":null,"userId":null,"name":"sample_name","surname1":null,"surname2":null,"login":null,"collegiateNumber":null,"nif":null,"email":"sample_email@sample.com","surname2Required":null,"telefonNumber":null,"birthDate":null,"inactive":false,"inactiveReason":null,"inactiveDate":null,"position":null,"professionals":null,"applications":null,"areas":null,"sexType":null,"locale":null,"password":null,"id":null}
但是我的 javascript 控制台一直显示这个错误,我不知道出了什么问题。
Uncaught SyntaxError: Unexpected token :
在响应的第 1 行。
怎么了?
谢谢。