我正在尝试发布(跨域)一些数据到jersey web服务并检索响应(一个GenericEntity对象)。post成功地映射到我的jersey端点,但是当我从请求中拉出参数时,它们是空的。
$ .ajax({
type: "POST",
dataType: "application/json; charset=utf-8",
url: jerseyNewUserUrl+'?jsoncallback=?',
data:{'id':id, 'firstname':firstname,'lastname':lastname},
success: function(data, textStatus) {
$('#jsonResult').html("some data: " + data.responseMsg);
},
error: function ( XMLHttpRequest, textStatus, errorThrown){
alert('error');
}
});这是我的球衣终点..
@POST
@Produces( { "application/x-javascript", MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path("/new")
public JSONWithPadding addNewUser(@QueryParam("jsoncallback")
@DefaultValue("empty")
final String argJsonCallback, @QueryParam("id")
final String argID, @QueryParam("firstname")
final String argFirstName, @QueryParam("lastname")
final String argLastName)我的$.ajax调用中是否遗漏了什么?
发布于 2010-06-16 00:32:09
试试这个:
$ .ajax({
type: "POST",
dataType: "jsonp",
jsonp: "fooCallBackFunction",
url: jerseyNewUserUrl,
data:{'id':id, 'firstname':firstname,'lastname':lastname},
success: function(data, textStatus) {
$('#jsonResult').html("some data: " + data.responseMsg);
},
error: function ( XMLHttpRequest, textStatus, errorThrown){
alert('error');
}
});发布于 2010-11-03 21:30:55
不能使用@QueryParam获取这些值。您可以使用对象来获取这些值。就像这样
@POST
@Produces( { "application/x-javascript", MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
@Path("/new")
public void addNewUser(User user){
//NB User has to have the following field names id', firstname,lastname
} https://stackoverflow.com/questions/3046903
复制相似问题