Jump to content

Set parameter in XSL using AJAX


john6384

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.