Hi, I hope this is the right place for this query, because it relates to PHP and AJAX.
I am having a lot of trouble trying to get a PHP page to successfully communicate with an AJAX script through XML. After a lot of googling, I have come across the following example:
The problem is when I return the body to XHR in my page, the resulting array is empty, but only when I use responseXML. When I use responseText all the XML body is there. Out of desperation, I have made my XHR code identical to the example, and that still did not make the code work. So then I looked at my php, and it appears that I cannot have anything else active in my php (such as required files, functions, function calls, conditional structures etc). When my php file only contains the XML header and the echoed XML body, the XHR xmlDoc.getElementsByTagName array is populated. I have tried to enable parts of my php to see if there are conflicts but there are none that I can see, and whenever I enable even the most trivial thing (such a junk function that echoes a string) the XML is not received by XHR.
As I understand it, XHR should not be aware of goings on the server side until it responds anyway, so I dont see how include files et al should have an effect on the XML being sent. And also, the above example does have a conditional structure in the php before the XML body is echoed. Why is this allowed, and yet my php page has to be devoid of any other code? I have even tried making the XML header and body be echoed from an include file, but this failed to work as well.
If anyone can let me know why this is, and if I am missing something in my understanding of how PHP and AJAX/XHR should interact when using XML, I would be very grateful.