Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript dn';找不到类的语法元素_Javascript_Xmlhttprequest_Jersey - Fatal编程技术网

Javascript dn';找不到类的语法元素

Javascript dn';找不到类的语法元素,javascript,xmlhttprequest,jersey,Javascript,Xmlhttprequest,Jersey,我有一个jersey服务,正在尝试使用xmlhttprequest调用它 @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public SomeJsonClass myService(SomeClassName classObject) throws RuntimeException, IOException, Interru

我有一个jersey服务,正在尝试使用xmlhttprequest调用它

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public SomeJsonClass myService(SomeClassName classObject) throws RuntimeException, IOException,
            InterruptedException {
//Some code to handle request
return jsonClassObject;
}

我试着用以下方式来称呼它:

 <!DOCTYPE html>
<html>
    <head>
        <title>jQuery</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    </head>
<body>

<p>Click the button to demonstrate the prompt box.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction()
{

    var json=prompt("Enter JSON");
    alert("JSON: "+json);

                var xhr = new XMLHttpRequest();
                xhr.open("post","http://localhost:8080/otp/rest/validate-otp");
                xhr.setRequestHeader("Content-Type","application/json;charset=UTF-8");
                xhr.responseType = "json";
                xhr.send(JSON.stringify(json));
}
</script>

</body>
</html>

jQuery
单击按钮以演示提示框

试试看

函数myFunction() { var json=prompt(“输入json”); 警报(“JSON:+JSON”); var xhr=new XMLHttpRequest(); xhr.open(“post”http://localhost:8080/otp/rest/validate-检察官办公室); setRequestHeader(“内容类型”,“应用程序/json;字符集=UTF-8”); xhr.responseType=“json”; send(JSON.stringify(JSON)); }
当我试着运行这段代码时,我得到一个“找不到类的语法元素”的警告。当我尝试使用rest客户端发送相同的json时,服务会给出正确的响应


这里可能有什么问题?

看看这篇文章——使用JAX-RS和Jersey的jQuery和Java的RESTful服务是否对您有帮助