我有一个从 AJAX 调用中检索到的 XML 对象,并为此做了一些操作:
$.ajax({
url: "url_of_xml",
type: 'GET',
dataType: 'xml',
success: function (xml) {
var sld_doc= $(xml)
// manipulations with the XML file
}
})
XML 文件已正确修改,并且是我需要的方式(使用添加/修改的节点)。现在我需要 POST 修改后的 XML(到 GeoServer 实例):
$.ajax({
url: "geoserver/rest/styles",
type: 'POST',
data: sld_doc,
headers: {
"Content-Type": "application/vnd.ogc.sld+xml"
},
dataType: 'json',
success: function (data) {a
console.log(JSON.stringify(data));
},
error: function (x, e) {
console.log(x.status + " " + x.responseText);
}
});
我收到错误:500 org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
根据我的阅读,它是由 XML 文档开头的标记之前的字符引起的。
如何清理 XML 对象的请求,以便正确发送到服务器?我可以访问节点,sld_doc.find("node_name")
但如何在第一个节点 ( <?xml>
) 之前检查无效字符?