0

我有一个这样的 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 调用是:

function hellowsfunction() {
    $.ajax({
        type: "GET",
        url:"http://localhost:8080/ehCS-ui/rest/hello/getUser",

        dataType: "json",

        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>

但是我的 javascript 控制台一直显示这个错误,我不知道出了什么问题。

Error. [object Object]

Web 服务还可以,但 Jquery 似乎没有读取 json obectj:这是 Web 服务在 bowser 上返回的用户对象。

{"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}

请帮我。多谢

4

1 回答 1

0

看起来你需要改变:

$('#lblResult').append('<p> deleted: ' + msg.setDeleted+ '</p>');

$('#lblResult').append('<p> deleted: ' + msg.deleted+ '</p>');
于 2013-06-17T16:35:31.733 回答