garethhall Posted October 21, 2009 Share Posted October 21, 2009 Hello Guys I have page I am working on but my xml object is null? well it's null when I do an alert? Can you guys see something work? Javascript var xmlHttp function getMemDetail(){ xmlHttp=GetXmlHttpObject() if(xmlHttp==null){ alert("Browser does not support HTTP Request"); return; } var qstr; qstr = "memID="+document.getElementById('members').value; xmlHttp.onreadystatechange = returnDetails; xmlHttp.open("POST","ajax/getMemberDetails.php?",true); xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlHttp.send(qstr); } function returnDetails(){ if(xmlHttp.readyState==4 ){ //alert(xmlHttp.responseText); //xmlDoc = xmlHttp.responseXML; alert(xmlHttp.responseXML); //WHY IS THIS NULL document.getElementById("toName").innerHTML = xmlDoc.getElementsByTagName("memFirstName")[0].childNodes[0].nodeValue; } } function GetXmlHttpObject(){ var xmlHttp=null; try{ // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); }catch (e){ // Internet Explorer try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }catch (e){ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp;} PHP <?php include("../../includes/cmsConfig.php"); include("../../includes/sharedFunctions.php"); auth(); $sql = "SELECT * FROM members WHERE memID = ".checkVars($_POST['memID']); $rs = mysql_query($sql ,$admin); $rw = mysql_fetch_assoc($rs); echo '<?xml version="1.0" encoding="ISO-8859-1"?>'; echo '<member>'; echo '<memName>'.$rw['memName'].'</memName>'; echo '<memFirstName>'.$rw['memFirstName'].'</memFirstName>'; echo '<memLastName>'.$rw['memLastName'].'</memLastName>'; // echo '<memAddress>'..'</memAddress>'; echo '</member>'; ?> Quote Link to comment Share on other sites More sharing options...
pastcow Posted October 21, 2009 Share Posted October 21, 2009 You might want to check the output of your XML, the line echo <?xml version="1.0" encoding="ISO-8859-1"?>'; looks slightly wrong. Make sure your <? are being printed correctly. You also appear to be missing a ' from the start of the echo Quote Link to comment Share on other sites More sharing options...
garethhall Posted October 21, 2009 Author Share Posted October 21, 2009 Sorry typo ' is present but the same fault. Quote Link to comment Share on other sites More sharing options...
garethhall Posted October 21, 2009 Author Share Posted October 21, 2009 Anyone please? Quote Link to comment Share on other sites More sharing options...
Robbrad Posted October 21, 2009 Share Posted October 21, 2009 Have you tried the echo statement like this echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> <member> <memName>".$rw['memName']."</memName> <memFirstName>".$rw['memFirstName']."</memFirstName> <memLastName>".$rw['memLastName']."</memLastName> </member>"; iv tested this in IE and it comes up as xml Quote Link to comment Share on other sites More sharing options...
garethhall Posted October 21, 2009 Author Share Posted October 21, 2009 Hi when I do alert(xmlHttp.responseText) this is my result <?xml version="1.0" encoding="UTF-8"?> <member> <memName>starwars</memName> <memFirstName>Luke</memFirstName> <memLastName>Hall</memLastName> </member> When I alert(xmlHttp.responseXML) I get null? I have since the last post change my php page and the code is like this now. <?php include("../../includes/cmsConfig.php"); include("../../includes/sharedFunctions.php"); auth(); $sql = "SELECT * FROM members WHERE memID = ".checkVars($_POST['memID']); $rs = mysql_query($sql ,$admin); $rw = mysql_fetch_assoc($rs); $xmltext = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<member></member>"; $xmlobj = simplexml_load_string($xmltext); $xmlobj->addChild("memName", $rw['memName']); $xmlobj->addChild("memFirstName", $rw['memFirstName']); $xmlobj->addChild("memLastName", $rw['memLastName']); print header("Content-type: text/plain") . $xmlobj->asXML(); ?> Quote Link to comment Share on other sites More sharing options...
garethhall Posted October 21, 2009 Author Share Posted October 21, 2009 Found the problem needed to set the content type to text/xml Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.