Javascript 在JQuery中使用POST时获取REST资源上的空值
我基本上是通过POST请求传递数据,但是资源端的值总是空的 以下是我的JQuery:Javascript 在JQuery中使用POST时获取REST资源上的空值,javascript,jquery,ajax,rest,post,Javascript,Jquery,Ajax,Rest,Post,我基本上是通过POST请求传递数据,但是资源端的值总是空的 以下是我的JQuery: function doUpdate(path, rdf) { var myObj = {"path": path, "rdf": rdf}; var sUrl = "http://localhost:8080/browsing/services/RDF/update"; $.ajax({ ty
function doUpdate(path, rdf)
{
var myObj = {"path": path, "rdf": rdf};
var sUrl = "http://localhost:8080/browsing/services/RDF/update";
$.ajax({
type: "POST",
url: sUrl,
contentType: "application/json",
data: myObj,
dataType: "json",
async: false,
success: function parse(resp, status, xhr) {
$("#message").html("STATUS: " + xhr.status + " " + xhr.statusText + "\n" + resp);
$("#message").hide();
$("#login_message").html("<font color='green'><b>Record succesfully updated</b></font>d");
},
error: function(resp, status, xhr){
$("#message").html("ERROR: " + resp.status + " " + resp.statusText + "\n" + xhr);
$("#message").show();
}
});
}
知道我做错了什么吗
谢谢
编辑
同样在Firefox中使用Poster,我在REST资源中看到空值,因此独立于我的Javascript代码,REST端似乎存在一些错误。删除数据类型:json,它将正常工作。您可以阅读如下内容
@POST
@XmlElement(name = "contentbean")
@Path("/update")
@Produces(MediaType.APPLICATION_JSON)
public void update(Contentbean contentbean) {
}
其中Contentbean是一个POJO类,根据您从ajax发送的数据使用@XmlRootElement进行注释。不幸的是,它仍然没有。我怀疑@QueryParam中是否存在问题@FormParampath可能会有所帮助。是否确定成功:函数解析?你在哪里看到了解析部分?@Oliboy50我一直用它来解析响应……效果很好。
@POST
@XmlElement(name = "contentbean")
@Path("/update")
@Produces(MediaType.APPLICATION_JSON)
public void update(Contentbean contentbean) {
}