A table I extract from a DB, have a column dedicated to the path of XML file. I need to open these xml from within the php.
First the column is shown:
<td><a href=\"#\" data-value=\"{$row[3]}\" onclick=\"submitdata(event)\">$row[2]</a></td>
Then a function submitdata(event) is called:
<script type='text/javascript'>
function submitdata(event){
var el=typeof( event.target )!='undefined' ? event.target : event.srcElement;
var data=document.getElementById('data');
data.value=el.dataset.value;
data.parentNode.submit();
}
</script>
And in the php:
if (function_exists('submitdata')){
$data = addslashes(strip_tags(@$_POST["data"]));
$myfile = fopen("$data", "r") or die("<h1>Unable to open file!</h1>");
$xml = fread($myfile,filesize("$data"));
$dom = new DOMDocument;
$dom->preserveWhiteSpace = TRUE;
$dom->loadXML($xml);
$dom->formatOutput = TRUE;
$xml_out = $dom->saveXML();
echo "<pre class=\"brush: xml\">";
echo htmlspecialchars($xml_out);
echo "</pre>";
fclose($myfile);
?>
<script type="text/javascript">
SyntaxHighlighter.all()
</script>
<?php
}
This code was working in a old server but I was not using the function_exists() because the xml was shown in another php page. This page's code was exactly the same code wrote above.
The request:
How do I open a XML file, through a link? Or, are there better alternatives?
EDIT:
I'm trying with Ajax, no luck so far.
I really appreciate any help in building the Ajax/jquery that can get the name of the file from the <href>
(or any other) and open the corresponding xml file in the same bootstrap's column.