Por parte del servidor obtener la ruta del archivo y muestras..
Código HTML:
Ver original <script type="text/javascript"> function seePdf(){
//todo tu ajax aca...
document.getElementById("pdf").setAttribute("src", respuestaAjax);
}
<embed src="RESPUESTA RUTA ACA" id="pdf" width="ancho" height="alto" />
Por php:
Código PHP:
Ver original<?php
$ruta = "tu/ruta"; // ruta completa sin / final
$pdf = $_POST["recurso"];
//o get no se cual usas...
$pdf = $_GET["recurso"];
/*
aca toda progra...
*/
echo "$ruta/$retornoDeTuProgra";
?>
Yo probé esto:
Código HTML:
Ver original <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript">
function createREQ() {
try {
req = new XMLHttpRequest(); /* p.e. Firefox */
}
catch(err1){
try {
req = new ActiveXObject('Msxml2.XMLHTTP'); /* algunas versiones IE */
}
catch (err2) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP"); /* algunas versiones IE */
}
catch (err3) {
req = false;
}
}
}
return req;
}
function mostrarpdf(){
var pdf = document.getElementById("pdf");
if(pdf.value == "0"){ alert("elija!!"); return false; }
var http = new createREQ();
http.open("POST", "seePdf.php", true);
http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
var archivo = document.getElementById("pdf").value;
http.send("archivo="+archivo);
http.onreadystatechange = function(){
if(http.readyState == 4 && http.status == 200){
var response = http.responseText;
document.getElementById("emb").setAttribute("src", response);
}
};
}
<select id="pdf" onchange="mostrarpdf();"> <embed src="" width="500" height="500" id="emb"/>
PHP:
Código PHP:
Ver original<?php
$ruta = "archivos/pdf"; //ruta sin / final
$archivo = $_POST["archivo"];
echo "$ruta/$archivo";
?>
y tengo un escritorio con los pdf...
usa eso como ejemplo, no se si es lo mejor, este es mi template de ajax