PC Nerd Posted February 2, 2008 Share Posted February 2, 2008 Hi, Im learnign AJAX - teaching myself, and Ive figured out that the PHP script isnt sending my data in XML format. My code is in following. <!--<xml version = '1.0'encoding = 'UTF-8' standalone = 'yes'>--> <xml version="1.0" encoding="utf-8"> <?php while($ROW = mysqli_fetch_assoc($QUERY)) { echo "<student id='".$ROW['Student_ID']."'>\n"; echo "<name>".$ROW['Name']."</name>\n"; ... ive had to block out the rest of the loop because it contains private ingformation - but I can garentee that it is returned as appearing as XML - ie the correct tags, and viewd in source etc. for those tha tknow AJAX - the responseXML is null, and then responseText returns what I want it to -= only its not in teh XML format. I have a feeling that its with the <xml> declaration at the topm but im not great with XML and Im not sure if there is an issue with that. Thanks for and all help Quote Link to comment Share on other sites More sharing options...
ratcateme Posted February 2, 2008 Share Posted February 2, 2008 i dont no much about phrasing xml in javascript but i thourght you had yo open it with something like this <?xml version="1.0" encoding="utf-8"?> insted of <!--<xml version = '1.0'encoding = 'UTF-8' standalone = 'yes'>--> <xml version="1.0" encoding="utf-8"> Scott. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted February 2, 2008 Author Share Posted February 2, 2008 hi i tried removeing the <!-- --> line but it made no difference. I had commented out my original xml tag because i thoguth the current one might work better = however there is no difference. any other suggestions? thanks for oyu help so far Quote Link to comment Share on other sites More sharing options...
ratcateme Posted February 2, 2008 Share Posted February 2, 2008 no you need to add the ? so this has ?'s at the start and end <?xml version="1.0" encoding="utf-8"?> Scott. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted February 2, 2008 Author Share Posted February 2, 2008 thats an issue- because its defined outside of PH - meanign tht php interprets it as an openin gphp tag - shot tag. ill play around with echoing it and escaping characters adn il let oyu knwo who i i go. thaks Quote Link to comment Share on other sites More sharing options...
ratcateme Posted February 2, 2008 Share Posted February 2, 2008 cant you just change the top of your code to this <?xml version="1.0" encoding="utf-8"?> <?php while($ROW = mysqli_fetch_assoc($QUERY)) { echo "<student id='".$ROW['Student_ID']."'>\n"; echo "<name>".$ROW['Name']."</name>\n"; ... Scott. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted February 2, 2008 Author Share Posted February 2, 2008 no my php is interpreting that as <? PHP CODE ?> - ie shot tags ive echoed it out and escaped characters and its still not working. eg: the page that AJAx connects to that returns XML is returnData.php if i go to it on firefox and i view the data in page source its all there. if i view page info in firefox... then i get: text/html if thats an issue - or its jsut firefox handling the xml then i dont know - but its just somethign I noticed. thaks for the suggestions- any other ideas? Quote Link to comment Share on other sites More sharing options...
ratcateme Posted February 2, 2008 Share Posted February 2, 2008 i see what you saying now i ran the code and got a error because of short tags but it works fine if i out this instead. <?php echo ' <?xml version="1.0" encoding="utf-8"?>'; ?> Scott. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted February 2, 2008 Author Share Posted February 2, 2008 echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; is what i have - and it works fine - as output. however im still getting it as html or text rather than XML - as noted previously. thanks anyway Quote Link to comment Share on other sites More sharing options...
ratcateme Posted February 2, 2008 Share Posted February 2, 2008 sorry i wasn't reading properly just add this at the top of your script to tell it it is XML header('Content-Type: text/xml'); Scott. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted February 2, 2008 Author Share Posted February 2, 2008 SOLVED!!!! thankyou thankyou thankyou thankyou thats fantastic looks like its now returning an XMl object.... now for me to generate hundreds of errors while learnign how to use it lol thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.