Código PHP:
var req;
function loadXMLDoc(url) {
// branch for native XMLHttpRequest object
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send(null);
// branch for IE/Windows ActiveX version
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send();
}
}
}
function processReqChange() {
// only if req shows "complete"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
// processing statements
response = req.responseXML.documentElement;
method = response.getElementsByTagName('method')[0].firstChild.data;
hora = response.getElementsByTagName('hora')[0].firstChild.data;
autor = response.getElementsByTagName('autor')[0].firstChild.data;
texto = response.getElementsByTagName('texto')[0].firstChild.data;
result = response.getElementsByTagName('result')[0].firstChild.data;
eval(method+'("'+hora+'","'+autor+'","'+texto+'")');
} else {
alert("There was a problem retrieving the XML data:\n" + req.statusText);
}
}
}
Pues me da un error en la segunda funcion, a la hora de traer el autor. Es esta linea
Código PHP:
autor = response.getElementsByTagName('autor')[0].firstChild.data;
Bueno si sirve de algo el XML es muy tonto:
Código PHP:
<?php
header('Content-Type: text/xml');
$aut=$_GET["autor"];
$txt=$_GET["texto"];
$hora=microtime();
?>
<?php echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'; ?>
<response>
<method>agregaFila</method>
<hora><?=urlencode($hora)?></hora>
<autor><?=urlencode($aut)?></autor>
<texto><?=urlencode($txt)?></texto>
<result>1</result>
</response>