Tengo problemas con la codificación de un fichero en una unidad compartida en otro pc, está en ANSI, que intento abrir desde el lado cliente con Microsoft.XMLHTTP. Siempre lo abre como UTF-8 por más que intento todo tipo de combinaciones GET, POST, META del HTML, CONTENT-TYPE y ACCEPT-CHARSET:
Código :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"lang="es" xml:lang="es"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <script language="javascript"> //AJAX (by Miguel Ángel Fuentes Casanova) var AJAXresponse=""; function getXmlHttpRequestObject() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); //NO IE } else if(window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); //IE } else { //NO AJAX alert("Navegador no compatible con AJAX!"); } } var AJAXreceiveReq = getXmlHttpRequestObject(); var AJAXQAfuncion = ""; function AJAXQueryAsincronaWeb(AJAXvalor,AJAXQAfuncionL) { AJAXreceiveReq = getXmlHttpRequestObject(); AJAXQAfuncion=AJAXQAfuncionL; if (AJAXreceiveReq.readyState == 4 || AJAXreceiveReq.readyState == 0) { if(AJAXvalor=="") { alert("No se ha indicado variable!!"); return; }; //AJAXreceiveReq.open("GET",AJAXvalor, false); AJAXreceiveReq.open("GET",AJAXvalor, true); AJAXreceiveReq.setRequestHeader("Accept-Charset", "ISO-8859-1;q=0.7"); //AJAXreceiveReq.setRequestHeader("Accept-Language", "sp,sp-sp,es,es-es;q=0.8"); //AJAXreceiveReq.setRequestHeader('Content-Type','text/plain; charset=iso-8859-1'); //AJAXreceiveReq.setRequestHeader('Content-Type','text/plain; charset=UTF-8'); //AJAXreceiveReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=ISO-8859-1'); //AJAXreceiveReq.setRequestHeader('Content-Type', 'text/plain; charset=windows-1252'); //para no IE: AJAXreceiveReq.overrideMimeType('Content-Type', 'text/plain; charset=iso-8859-1'); AJAXresponse=""; AJAXreceiveReq.onreadystatechange = AJAXWebLista; try { AJAXreceiveReq.send(null); } catch (er) { alert("No se puede contactar con el servidor"); return true; }; } } //Lamado sólo cuando se ha cargado la web: function AJAXWebLista() { if (AJAXreceiveReq.readyState == 4) { AJAXresponse=AJAXreceiveReq.responseText; eval(AJAXQAfuncion); } } function miQueryOK() { alert(AJAXresponse); //document.write(AJAXresponse); }; </script> </head> <body> AJAX Demo by Michael! <input type="text" name="foo" value="file://c:/mi_fichero_ansi.txt!"> <input type="button" name="btnfoo" value="carga Web onlineMENTE ;P" onclick="javascript:AJAXQueryAsincronaWeb(document .all.foo.value,'miQueryOK()');"> </body> </html>
Gracias por adelantado! Miguel Ángel.