Results 1 to 6 of 6
-
05-22-2006, 03:38 AM #1Newbie
- Join Date
- Sep 2004
- Posts
- 16
AJAX: Weird problem. (PHP-XML-> JS) XML not parsed properly
Hello,
I have created AJAX based Appplication in PHP
All works fine... Data is "posted" to the php script.
Data is processed
XML with proper data is created through the PHP Script (I have checked the same personally. The data is just right)
However, when I use JS to read the data back on the same HTML form on different fields, improper data is being shown.
Due to this, the application is not running as expected.
I again confirm, that the XML generated in PHP is perfect with the tags and data values...
I would appreciate if someone could throw some light on why this is happening.
Thank you.
Best Regards,
Monil C
-
05-22-2006, 05:32 AM #2Web Hosting Master
- Join Date
- Jul 2003
- Location
- Kuwait
- Posts
- 5,104
What is shown, and what do you expect? Post some code please, we can't help you without seeing code.
-
05-22-2006, 05:57 AM #3Newbie
- Join Date
- Sep 2004
- Posts
- 16
Hi,
The PHP Script creates proper XML
//Collect Posted variables.
// Process them
// Create XML
$return_value = '<?xml version="1.0" standalone="yes"?><Data><a>123.33</a><b>10</b><c>1234567</c></Data>';
header('Content-Type: text/xml');
echo $return_value;
function handleHttpResponse() {
if (http.readyState == 4) {
if (http.responseText.indexOf('invalid') == -1) {
// Use the XML DOM to unpack the city and state data
var xmlDocument = http.responseXML;
var a = xmlDocument.getElementsByTagName('a').item(0).firstChild.data;
var b = xmlDocument.getElementsByTagName('b').item(0).firstChild.data;
var c = xmlDocument.getElementsByTagName('c').item(0).firstChild.data;
document.getElementById('a').value = a;
document.getElementById('b').value = b;
document.getElementById('c').value = c;
isWorking = false;
}
}
}
It posts 0, 0.45, 443
I just dont understadn what is wrong...
Thanks.
-
05-22-2006, 03:40 PM #4Web Hosting Master
- Join Date
- Jul 2003
- Location
- Kuwait
- Posts
- 5,104
when you alert() the data, does it show the correct value?
Here is the example that I tried with your XML, and it worked fine:
Code:<html> <head> <script type="text/javascript"> function test() { alert(xmlDoc.getElementsByTagName('a').item(0).firstChild.data); } if (document.implementation && document.implementation.createDocument) { xmlDoc = document.implementation.createDocument("", "", null); xmlDoc.onload = test; } else if (window.ActiveXObject) { xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.onreadystatechange = function () { if (xmlDoc.readyState == 4) test() }; } else { alert('Your browser can\'t handle this script'); } xmlDoc.load("test.xml"); </script> </head> <body><p>Hello</p></body> </html>
Code:<?xml version="1.0" standalone="yes"?><Data><a>123.33</a><b>10</b><c>1234567</c></Data>
-
05-23-2006, 08:34 AM #5WHT Addict
- Join Date
- May 2006
- Posts
- 134
Its a good idea to check the status code returned from the AJAX request, using the above example:
if (xmlDoc.readyState == 4) test()
if (xmlDoc.readyState == 4 && xmlDoc.status == 200) test()
-
05-23-2006, 11:52 AM #6Newbie
- Join Date
- Sep 2004
- Posts
- 16
Thank you for the replies...