【发布时间】:2015-04-22 19:15:06
【问题描述】:
我创建了一个 RestEasy Web 服务,并使用 Get Method 并使用 http://localhost:8080/rest/search?name=foo 之类的 URI 将参数传递给服务,并通过使用 @QueryParam,它工作正常: 注意:我正在使用 ajax 调用来调用 Web 服务
@GET
@Path("/search")
@Consumes({"application/xml", "application/json", "text/plain"})
@Produces( MediaType.TEXT_PLAIN)
public JSONArray getDetails(@QueryParam("name") String name) {
//my code here
}
我的 ajax 调用
$.ajax({
type : 'get',
url : searchURL,
headers : { 'SM_USER' : userId },
dataType : 'json',
success : function(data) {
现在我必须将方法从 GET 更改为 POST,在这种情况下,它不接受 URI 参数,现在我以不同的方式尝试了它,例如: 现在我通过 ajax 数据传递值。 Ajax 调用:
$.ajax({
type : 'post',
url : searchSuppURL,
headers : { 'SM_USER' : userId},
contentType: "application/json",
data: { 'name' : 'foo'},
dataType : 'json'
success : function(data) {
网络服务代码:
@POST
@Path("/search")
//@Consumes({"application/x-www-form-urlencoded"})
@Consumes({"application/xml", "application/json", "text/plain"})
@Produces( MediaType.TEXT_PLAIN)
public JSONArray getDetails(String name) {
数据现在可供服务使用,但格式不正确我已将其 sysout
System.out.println("name...." +name);
不是打印 name....foo 而是打印 name....name=foo
我没有得到我缺少的任何建议...
提前致谢
【问题讨论】:
标签: ajax json rest jax-rs resteasy