在JQuery中使用POST时,在REST资源上获取null值

Getting null values on REST Resource when consuming POST in JQuery

本文关键字:资源 获取 null REST JQuery POST      更新时间:2023-09-26

我基本上是通过POST请求传递数据,但REsource端的值总是空的。

这是我的JQuery:

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();
                }
            });
        }

以及REST资源:

@POST
    @XmlElement(name = "contentbean")
    @Path("/update")
    @Produces(MediaType.APPLICATION_JSON)
    public void update(@QueryParam("path") String Path, @QueryParam("rdf") String Content) {
        ...     
    }

知道我做错了什么吗?

谢谢,

编辑

同样在Firefox中使用Poster,我在REST资源上看到了null值,因此独立地形成了我的Javascript代码,在REST方面似乎存在一些错误。

删除数据类型:"json",,它将在

中工作

您可以阅读以下

@POST
@XmlElement(name = "contentbean")
@Path("/update")
@Produces(MediaType.APPLICATION_JSON)
public void update(Contentbean contentbean) {
}

其中Contentbean是一个(POJO)类,根据您从ajax发送的数据用@XmlRootElement进行注释。