Jump to content

parse response


birbal

Recommended Posts

i am trying to get response of a ajax request as xml. but i am getting undefined in responseXML where as response as a text is giving the desired output. the file where ajax is requesting is a php file which generates a xhtml page.what i am missing? how can achive it?another problem is how can i parse the reponsetext by tags name or node name?

Link to comment
Share on other sites

i am trying to get response of a ajax request as xml. but i am getting undefined in responseXML where as response as a text is giving the desired output. the file where ajax is requesting is a php file which generates a xhtml page.what i am missing? how can achive it?another problem is how can i parse the reponsetext by tags name or node name?
for the second problem you can pass the string to this functionfunction parseXml(xml){ var xmldom = null; if (typeof DOMParser != "undefined"){ xmldom = (new DOMParser()).parseFromString(xml, "text/xml"); var errors = xmldom.getElementsByTagName("parsererror"); if (errors.length){ throw new Error("XML parsing error:" + errors[0].textContent); } } else if (document.implementation.hasFeature("LS", "3.0")){ var implementation = document.implementation; var parser = implementation.createLSParser(implementation.MODE_SYNCHRONOUS, null); var input = implementation.createLSInput(); input.stringData = xml; xmldom = parser.parse(input); } else if (typeof ActiveXObject != "undefined"){ xmldom = createDocument(); xmldom.loadXML(xml); if (xmldom.parseError != 0){ throw new Error("XML parsing error: " + xmldom.parseError.reason); } } else { throw new Error("No XML parser available."); } return xmldom; }then you use dom so root = xmldom.documentElement then use DOM to get the elements for example root.getElementsByTagName('child')for the first one you need to send the code
Link to comment
Share on other sites

thanks for the help justsomeguy and abdelebouhy.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...