GURAQTINVU Posted November 28, 2008 Share Posted November 28, 2008 OK, I've tried solo, but as it's not my day job, I'm now asking (N.B. This really is a php question I think, honestly). I have an Ajax test project below that firstly attaches a functon to 'on-click' events - successfully (in principle). When a link is clicked, the 'on-click' function uses XMLHttpRequest (via client Javascript) to try to open that PHP file (on the server), which through a 'case' construct choses the correct XML file, which it SHOULD pass back, which should (via client Javascript) parse as required. OK, it doesn't. The problem seems to be in the use of the intermediate PHP file - because it all works if the XML file is hard wired into the 'on-click' function. I'm sure the main problem is in the headers that are sent or recieved (or not) but this is not my forte and I haven't been able to find anyone who is using this same route, which aims to degrade gracefully if Javascript is off on the client (I have succesfully implemented the solution of PHP parsing for when it is off). function PrepareLinks() { if (!document.getElementById || !document.getElementsByTagName) {return;} if (!document.getElementById("mylist")) {return;} var list = document.getElementById("mylist"); var links = list.getElementsByTagName("a"); for (var i=0; i<links.length; i++) { links.onclick = function() { var queryPageID = this.getAttribute("href").split("?")[1]; //get the value of query string 'page' var url = "siteCompletePageDetails.php?"+queryPageID; if (grabFile(url) == true) {return false;} else {return true;} } } } function grabFile(file) { var request = getHTTPObject(); if (request) { request.onreadystatechange = function() { parseResponse(request); }; request.open("GET", file, true); request.send(null); return true; } else { return false; } } function parseResponse(request) { if (request.readyState == 4) { if (request.status == 200 || request.status == 304) { var data = request.responseXML; . . . . . . } } } //siteCompletePageDetails.php <?php if (isset($_GET["page"])) { //Only true when a link is clicked and Javascript is ON, and DOM fully supported in Browser and Div tags available. switch ($_GET["page"]) { case "testFile": include "testFile.xml"; break; } } ?> Please help if you can - thanks. :-\ Link to comment https://forums.phpfreaks.com/topic/134645-php5-js-xml-and-ajax-is-good-for-hair-loss/ Share on other sites More sharing options...
Mchl Posted November 28, 2008 Share Posted November 28, 2008 case "testFile": include "testFile.xml"; Is 'testFile.xml' a PHP script? Link to comment https://forums.phpfreaks.com/topic/134645-php5-js-xml-and-ajax-is-good-for-hair-loss/#findComment-701052 Share on other sites More sharing options...
GURAQTINVU Posted November 28, 2008 Author Share Posted November 28, 2008 No, it's a simple xml file: <?xml version="1.0" encoding="utf-8"?> <details> <name> <paras>1</paras> <paras>2</paras> <paras>3</paras> </name> </details> Link to comment https://forums.phpfreaks.com/topic/134645-php5-js-xml-and-ajax-is-good-for-hair-loss/#findComment-701057 Share on other sites More sharing options...
Mchl Posted November 28, 2008 Share Posted November 28, 2008 So using inlude() with it will not give you desired reults. Use file_get_contents and then echo it Link to comment https://forums.phpfreaks.com/topic/134645-php5-js-xml-and-ajax-is-good-for-hair-loss/#findComment-701062 Share on other sites More sharing options...
rhodesa Posted November 28, 2008 Share Posted November 28, 2008 So using inlude() with it will not give you desired reults. Use file_get_contents and then echo it or just use readfile() Link to comment https://forums.phpfreaks.com/topic/134645-php5-js-xml-and-ajax-is-good-for-hair-loss/#findComment-701079 Share on other sites More sharing options...
GURAQTINVU Posted November 29, 2008 Author Share Posted November 29, 2008 Thanks for both suggestions firstly, but have to report back no success. The responseXML always comes back basically empty, although the string is in responseText - but I think this is not new. By the by, the 'type' of responseXML that is retuned is IXMLDOMDocument2, which means very little to me. I am trying to avoid parsing simple text as XML is supposed to have done all the hard work in essence. Link to comment https://forums.phpfreaks.com/topic/134645-php5-js-xml-and-ajax-is-good-for-hair-loss/#findComment-701673 Share on other sites More sharing options...
haku Posted November 29, 2008 Share Posted November 29, 2008 Are you testing in firefox? You need to add a couple extra headers for firefox to parse the response as XML and not as text. Link to comment https://forums.phpfreaks.com/topic/134645-php5-js-xml-and-ajax-is-good-for-hair-loss/#findComment-701676 Share on other sites More sharing options...
GURAQTINVU Posted November 29, 2008 Author Share Posted November 29, 2008 Don't mock, but I am by default testing in IE7 & 8 (of all things - and with their new firebug equivalent - it's in colour as opposed to firebug). Link to comment https://forums.phpfreaks.com/topic/134645-php5-js-xml-and-ajax-is-good-for-hair-loss/#findComment-701698 Share on other sites More sharing options...
GURAQTINVU Posted December 1, 2008 Author Share Posted December 1, 2008 N.B. Actually, I also originally tested in Firefox to no avail, but for me it is not testimony to much other than I had bugs of one sort or another then too, and that these too may or may not exist in the lastest inevitably tweaked attempt to get it working. Link to comment https://forums.phpfreaks.com/topic/134645-php5-js-xml-and-ajax-is-good-for-hair-loss/#findComment-703020 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.