Javascript OpenLayers.Request.Post中没有XMLDocument
我使用异步OpenLayers POST请求并通过responseText获取以下字符串:Javascript OpenLayers.Request.Post中没有XMLDocument,javascript,xml,openlayers,Javascript,Xml,Openlayers,我使用异步OpenLayers POST请求并通过responseText获取以下字符串: <?xml version="1.0" encoding="UTF-8"?> <gml:TimePeriod xmlns:gml="http://www.opengis.net/gml"> <gml:beginPosition>2011-10-18T15:15:00.000+02:00</gml:beginPosition> <gml:endPosi
<?xml version="1.0" encoding="UTF-8"?>
<gml:TimePeriod xmlns:gml="http://www.opengis.net/gml">
<gml:beginPosition>2011-10-18T15:15:00.000+02:00</gml:beginPosition>
<gml:endPosition>2014-11-23T14:45:00.000+01:00</gml:endPosition>
</gml:TimePeriod>
//xml回调处理程序
function handler(request) {
var xmlText = request.responseText;
console.log(xmlText); //returns the string above
var xmlDoc = request.responseXML;
console.log(xmlDoc); // returns the empty XMLDocument
var timeArray = xmlDoc.getElementsByTagName('TimePeriod');
console.log("timeArray:",timeArray);
};
//创建XML文档
function CreateXMLDocument () {
var xmlDoc = request.responseText;
if (window.DOMParser) {
var parser = new DOMParser();
xmlDoc = parser.parseFromString (xmlDoc, "text/xml");
} else if (window.ActiveXObject) {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.loadXML (xmlDoc);
}
var TimeNode = xmlDoc.getElementsByTagName ("TimePeriod");
var beginPosition = TimeNode.getAttribute ("beginPosition");
alert ("The Timeperiod is " + beginPosition);
}
你知道如何将“TimePeriod”标记放入对象“timeArray”中吗?
为什么请求对该字符串输出有效而对XMLDocument无效?我已经弄明白了!
通过更改几行代码,我在警报中收到了请求的时间段。
我交换了XML警报处理程序代码,没有使用XML回调处理程序
//xml警报处理程序
function handler(request) {
var xmlStr = request.responseText;
console.log("xmlStr:",xmlStr);
var parser=new DOMParser();
var xmlDoc=parser.parseFromString(request.responseText,"text/xml");
var gml = xmlDoc.getElementsByTagName("gml:beginPosition")[0].firstChild.data;
console.log("gml:beginPosition", gml);
alert(gml);
};
function handler(request) {
var xmlStr = request.responseText;
console.log("xmlStr:",xmlStr);
var parser=new DOMParser();
var xmlDoc=parser.parseFromString(request.responseText,"text/xml");
var gml = xmlDoc.getElementsByTagName("gml:beginPosition")[0].firstChild.data;
console.log("gml:beginPosition", gml);
alert(gml);
};