I just played around with some Ajax examples, but have problems parsing XML data with JavaScript.
The XML file sent by the PHP script looks like this:
Code: Select all
<?xml version="1.0" encoding="ISO-8859-1" standalone="true" ?>
<update>
<id>element</id>
<content>some content...</content>
</update>Code: Select all
header("Content-Type: text/xml");
header("Vary: Accept");Code: Select all
function handleResponse() {
if (reqObj.readyState == 4) {
if (reqObj.status == 200) {
var response = reqObj.responseXML.documentElement;
var id = response.getElementsByTagName("id").item(0).firstChild.data;
var content = response.getElementsByTagName("content").item(0).firstChild.data;
document.getElementById(id).innerHTML = content;
}
}
}Code: Select all
AJAX
http://localhost/sandbox/AJAX/
Unknown thread
Error:
name: TypeError
message: Statement on line 57: Could not convert undefined or null to object
Backtrace:
Line 57 of inline#1 script in http://localhost/sandbox/AJAX/
var id = (response.getElementsByTagName("id").item(0)).firstChild.data;
At unknown location
[statement source code not available]Code: Select all
var response = reqObj.responseXML.documentElement;Code: Select all
var response = reqObj.responseHTML;
alert(response);Lars