Javascript dn';找不到类的语法元素
我有一个jersey服务,正在尝试使用xmlhttprequest调用它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
@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服务是否对您有帮助