birbal Posted April 3, 2011 Share Posted April 3, 2011 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 More sharing options...
justsomeguy Posted April 4, 2011 Share Posted April 4, 2011 The content type of the response needs to be text/xml, or another XML mime type. If it's anything else, the response goes in responseText. Link to comment Share on other sites More sharing options...
abdelelbouhy Posted April 4, 2011 Share Posted April 4, 2011 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 More sharing options...
birbal Posted April 5, 2011 Author Share Posted April 5, 2011 thanks for the help justsomeguy and abdelebouhy. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.