1
Hello, I’m studying a little "communication" between php and javascript, I’m very beginner and I’m a few days with a problem that I can not solve, in php I’m generating an xls with data from BD
function buscaLocalizacoes($conexao){
$resultado = mysqli_query($conexao, "SELECT * FROM marcas");
$manipulador_arq = fopen("C:\\xampp\\htdocs\\04072016\\marker.xml","w+");
@fwrite($manipulador_arq,"<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n\n\n<mapa>");
while($marca = mysqli_fetch_array($resultado)){
$xml = "\n\n<marker>\n";
$xml .= "<id>$marca[0]</id>\n";
$xml .= "<titulo>$marca[1]</titulo>\n";
$xml .= "<latitude>$marca[2]</latitude>\n";
$xml .= "<longitude>$marca[3]</longitude>\n";
$xml .= "</maker>";
@fwrite($manipulador_arq,$xml);
}
@fwrite($manipulador_arq,"\n\n</mapa>");
However I can not read this in javascript, I know it is possible by my searches but the file keeps loading as null in the application, follows the JS code
function loadXMLDoc() {
req = false;
if(window.XMLHttpRequest && !(window.ActiveXObject)) {
try {
req = new XMLHttpRequest();
} catch(e) {
req = false;
}
} else if(window.ActiveXObject) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
req = false;
}
}
}
if(req) {
var url = "file:///C:/xampp/htdocs/04072016/marker.xml";
req.open("GET", url , true);
return myFunction(req);
}
}
The idea is that he sends the xml file to that "myFunction".
If you want to use Javascript as PHP then you should use Node.js, which is the server version of Javascript. Using the browser you will have problems opening local files with
"file:///
– Sergio
For security requirements Javascript cannot request files from the user’s computer accessing the page. In your case recommend installing Apache, Mysql and PHP so that you access the application from
http://localhost/pagina.php
.– user21448