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); Quote Link to comment 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. Quote Link to comment 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. 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.