Jump to content

[SOLVED] Cant read XML data


garethhall

Recommended Posts

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

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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();
?>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.