Forum Moderators: open
alright I'm posting to a php page which works fine the php page gets the input does some stuff then outputs some xml. The problem is at the end when I want to retrieve the XML output in the processrequestchange function when I ask for responseXML null is always returned.
Here's my javascript
if (window.XMLHttpRequest) {//mozilla
req = new XMLHttpRequest();
req.open("POST", url, true);
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
req.send(username + "&" + password);
req.onreadystatechange = processReqChange;
// branch for IE/Windows ActiveX version
}
function processReqChange(){
// only if req shows "complete"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
response = req.responseXML.documentElement;//this line won't work always returns null
//var response = req.responseText; if I were to execute this line instead of the response xml I get the xml in text that I wanted to be output so I know my php file is outputting the right thing
} else {
alert("There was a problem retrieving the XML data:\n" + req.statusText);
}
}//end if ready
}//end processReqChange
Here's the XML that is output
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<response>
<method>checkName</method>
<result> result </result>
</response>
I think my problem might be my xml isn't validating because it doesn't have a doctype (however I can't get it to validate with one either) therefore when I request XML from the browser NULL is returned to it. If anyone has any ideas as to what I'm doing wrong it'd be appreciated.
Also if anyone knows of an example of xml that validates so I could test with that it would be appreciated
The best solution is using this tutorial just to be SAFE.
AJAX XML Tutorial [designplanet.biz]