john6384 Posted November 13, 2007 Share Posted November 13, 2007 I am trying to set a parameter in my XSL to be a PHP variable that I know is working as it can be seen using an alert in the AJAX. Element keeps coming through as empty - javascript error. Any more code, explanation needed then please say. Cheers var username = '<?php echo $username;?>'; var myXMLHTTPRequest = new XMLHttpRequest(); var myXSLTProcessor = new XSLTProcessor(); alert(username); //load the XSL file myXMLHTTPRequest.open("GET", "mnu.xsl", false); myXMLHTTPRequest.send(null); //get the XML document xslStylesheet = myXMLHTTPRequest.responseXML; myXSLTProcessor.importStylesheet(xslStylesheet); //load the xml file myXMLHTTPRequest.open("GET", "mnu.xml", false); myXMLHTTPRequest.send(null); var xmlSource = myXMLHTTPRequest.responseXML; alert(myXMLHTTPRequest.responseText); myXSLTProcessor.setParameter(null, "username", username); fragment = myXSLTProcessor.transformToFragment(xmlSource, document); var element = document.getElementById("menuTarget"); while(element.firstChild) { element.removeChild(element.firstChild); } element.appendChild(fragment); Link to comment https://forums.phpfreaks.com/topic/77110-set-parameter-in-xsl-using-ajax/ Share on other sites More sharing options...
john6384 Posted November 13, 2007 Author Share Posted November 13, 2007 I think that it is to do with the order that my code executes i.e. element has not been populated or assigned anything before it is used - this gives an empty. To solve this I tried to make the whole of the code shown a function that is called after another function is used to setup the page - point of this was to make element not empty. This did not work - please suggest how I can debug this or any other ideas. Link to comment https://forums.phpfreaks.com/topic/77110-set-parameter-in-xsl-using-ajax/#findComment-390537 Share on other sites More sharing options...
john6384 Posted November 13, 2007 Author Share Posted November 13, 2007 Solved - put a function in main JS file that so that element is populated. Link to comment https://forums.phpfreaks.com/topic/77110-set-parameter-in-xsl-using-ajax/#findComment-390540 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.