I don't know PHP, but I don't see where you're getting your closing tag for the <confession>
element. Call me confused, since you say the output is well-formed...
Do yourself a favor, and use a JS library that wraps all the ajax magic for you. There's a lot of cross-browser issues and gotchas, and this may just be one of those things.
I'd recommend jQuery, it's the easiest and quite powerful. So add this to the top of your html, inside the head tag:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
And then in your JS do something like this:
$.get('/leer/confesiones/', function(data) {
console.log(data);
});
That should get you started. Look here for more info about jQuery and the $.get function. BTW- I see you're using a POST, but for retrieval of data (no updating or deleting) the convention is GET.
Additionally, consider changing your PHP so that it returns JSON formatted data instead of XML. So instead of doing that little dance you have to do with the xml markup, just get an array ready with all the data, and do this:
echo json_encode($array); // voila
if (typeof window.ActiveXObject != 'undefined' ) {
I'd go for native XMLHttpRequest first. ActiveXObject should only be a fallback, as it may generate ugly ActiveX warnings.
http = new ActiveXObject("Microsoft.XMLHTTP");
Accidental global. Rememeber to use var
.
http.onreadystatechange = oncomplete;
onreadystatechange
is called in more cases than just completion. You should only call oncomplete
when readystatechange
fires and readyState===4
, otherwise you may be attempting to parse incomplete or missing XML.
http.onload = oncomplete;
onload
is not part of the XMLHttpRequest standard. You should use onreadystatechange
for both branches.