javascript - No XMLDocument from OpenLayers.Request.Post -


i use asynchronous openlayers post request , via responsetext string:

<?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> 

for reason not response in xml document object, respectively got empty xmldocument.

my code far:

var request = openlayers.request.post({                     url: "http://139.17.3.305:8080/database/sos",                     async: true,    //is default                     data: xmlstring,                     callback: handler   //name of triggered callback function                 }); 

//xml callback handler

function handler(request) {                      var xmltext = request.responsetext;                          console.log(xmltext); //returns string above                       var xmldoc = request.responsexml;                      console.log(xmldoc);   // returns empty xmldocument                          var timearray = xmldoc.getelementsbytagname('timeperiod');                             console.log("timearray:",timearray);                    };  

// create xml document

 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 " + beginposition);   } 

any idea how “timeperiod” tag objekt “timearray”? why request work string output , not xmldocument?

i've figured out! received requested time period in alert changing few line of code. exchanged xml alert handler code , left xml callback handler out.

//xml alert handler

                  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);                   };  

Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -