Function downloadUrl( ) in JAvaScript no working

Hi, I am adapting a code that I had in pure PHP to Cakephp, but the problem that I found is the following: I had a file where I passed some records retrieved from a table to XML, this file was downloaded with JavaScript, using the function downloadUrl( ) this is to pass some data to the Google Maps API.

As I said in pure PHP works, the problem is that I do not know where to put this file in Cakephp As a view? As an element? And how do we call it from the downloadUrl() function? DownloadUrl(‘documentoxml’)?

documentoxml:

<!-- Start XML file, echo parent node -->
	<?= '<documentos>'; ?>

<!-- Iterate through the rows, printing XML nodes for each -->
	<?php foreach($documentos as $documento): ?>

<!-- ADD TO XML DOCUMENT NODE -->
      <?= '<documento '; ?>
        <?= 'id="'.$documento->id.'" '; ?>
        <?= 'foto="'.$documento->imagen.'" '; ?>
        <?= 'nombre="'.$documento->nombre.'" '; ?>
        <?= 'texto="'.$documento->texto.'" '; ?>        
	<?= '</documento>'; ?>

	<?php endforeach; ?>

 <!-- End XML file -->
 	<?= '</documentos>'; ?>

Function downloadUrl( ):

downloadUrl("documentoxml", function(data) {
		var xml = data.responseXML;
   		var documentoxml = xml.documentElement.getElementsByTagName('documentoxml');
            ......
}

Not sure what you’re trying to do. So you have a table, read it and create an XML from that data? That means you read the table in the controller-action, set it as View-variable and the XML creation is done in a .ctp template.

You should also check out:

Now you want to put a JS function somewhere to call it? You can drop it into the same template if it’s a shorter snippet. Or you load it from an external JS-file. Depends on your style of implementing it.

1 Like

Thak you!! In the end, the solution will create an element that passes the array of the table and does not use the function downloadUrl( ), but will go directly to the element.

Function downloadUrl( ):

/*downloadUrl("documentoxml", function(data) {
			var xml = data.responseXML;*/

   		var documentoxml = document.getElementsByTagName('documentoxml');