我必须通过Ajax发送一个xml,并发出POST HTTP调用。
我不知道如何格式化文本,如果有必要,例如JSON.parse()。我试图将我的xml示例放入js var中。我认为这是不正确的,但我不知道该怎么做。
有人可以帮助我吗?
这是我用tomcat服务器进行调用的jsp页面:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Send jSon - put method</title>
</head>
<body>
<script>
var peopleXml = "<person><address>prova 56</address><name>prova 1</name> <surname>prova cognome</surname></person>";
function SaveObjectXML(){
$.ajax({
type: "POST",
url: "http://localhost:8080/HibernateTutorialWeb/rest/person/postXml",
data: peopleXML,
contentType: "application/json; charset=utf-8",
dataType: "xml",
success: function(data){alert(data);},
failure: function(errMsg) {
alert(errMsg);
}
});
}
</script>
<br><h2>XML</h2>
<br><input type="button" onclick="SaveObjectXML()" value="Inserisci una persona"/>
<div id = "footer">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js">
</script>
</div>
</body>
</html>
答案 0 :(得分:2)
您是否尝试发送json或xml?
//group[@name='testy_"group"_1515083335']
您应该尝试将其更改为:contentType: "application/json; charset=utf-8",