Ciao.
Scusate mi potreste fare un esempio di come e quando
viene usata una cosa del genere
Codice PHP:var req = new XMLHttpRequest();
req.open('GET', 'file:///home/user/file.json', false);
req.send(null);
if(req.status == 0)
dump(req.responseText);
![]()
Ciao.
Scusate mi potreste fare un esempio di come e quando
viene usata una cosa del genere
Codice PHP:var req = new XMLHttpRequest();
req.open('GET', 'file:///home/user/file.json', false);
req.send(null);
if(req.status == 0)
dump(req.responseText);
![]()
Without faith, nothing is possible. With it, nothing is impossible
http://ilwebdifabio.it
se funzionasse on-line sarebbe un cratere nella sicurezza ... son quasi certo tu abbia preso quel link da firebug o tamperdata dopo aver chiamato un file in locale ... oppure, semplicemente, è una porzione di script che lavora in locale e solo in quella cartella e che funziona solo su FireFox o altri diversi da IE ma non da web, solo da locale.
Aggiungo che non essendoci un webserver dietro, capace di restituire lo stato della request ed interpretare la richiesta è normale che venga fatto il check a status 0 poichè di certo non sarà il filesystem a modificarlo (legge da locale, punto)
[edit]
P.S. quella è una chiamta sincrona, più che Ajax trattasi di Sjax .... se è l'if sullo status immediatamente dopo il send che ti dava pensiero![]()
Ho trovato il tutto qui
Per curiosità ho fatto una prova (primo codice che
mi è venuto alla mano)
ma FF diceCodice PHP:<script language="JavaScript" type="text/JavaScript">
var req = null;
function processReqChange() {
if(req.status == 0)
alert(req.responseText);
}
function loadUrl( url ) {
if(window.XMLHttpRequest) {
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) {
req.onreadystatechange = processReqChange;
req.open('GET', url, true);
req.send('');
}
}
window.onload= function(){
loadUrl('file:///home/post.txt');
}
</script>
Il file l'ho messo in F:\homeAccess to 'file:///home/post.txt' from script denied
mi pesco qc?
![]()
Without faith, nothing is possible. With it, nothing is impossible
http://ilwebdifabio.it
quello è un'esempio sincrono, non asincrono, e carica un file locale ... non va bene per Ajax on-line e lo status, online, difficilmente sarà 0 se si chiama una pagina web ... direi praticamente mai.
P.S. non so chi abbia editato nel frattempo ma io li leggo richieste a pagine URL , non a file locali, con verifica dello status giustamente a 200 e non a 0
ma non è un bug .. è stra normale che sia così ... ma che stanno facendo in MDC? :master:Note: file:/// and ftp:// do not return HTTP status, which is why they return zero for status and an empty string for statusText. Refer to bug 331610 for more insight.
[edit]
ah ... ok, era il tipo del bug che non ha capito molto di HTTP
status zero è corretto ed è solo per un uso locale ... ma in generale AJax ha poco senso per un uso in locale, non esistono problemi di bandwidth ne di status quindi il readystate è praticamente inutile, si usa sincrono e al limite si fa un try catch dato che si lavora in locale e non c'è HTTP su filesystem quindi quell'esempio è corretto ma se si leggono anche le note si capisce perchè è li e a cosa serveIt's debatable that the file:// protocol handler should do that. It's not a web
server; it's simply an interface to your local filesystem, just the same as
ftp:// shouldn't return HTTP status codes.
I suggest that XMLHttpRequest should either work differently (i.e. no statuses,
although I can't see the effectiveness of this) or not at all with protocols
other than http://.![]()
Thanks![]()
![]()
Without faith, nothing is possible. With it, nothing is impossible
http://ilwebdifabio.it
Ehm, "file:///home/post.txt" dubito che possa riferirsi a "F:\home"... Mi sembra tanto un path Unixiano che si riferisce a "/home/post.txt" che su window non ha molto senso :ignore:Originariamente inviato da whisher
Il file l'ho messo in F:\homeCodice PHP:loadUrl('file:///home/post.txt');
mi pesco qc?
Comunque cose simili non sara' mai possibile farle, se non sfruttando bug o in altri modi vietati qua sul forum.
Ultima modifica ad opera dell'utente /dev/null il 01-01-0001 alle 00:00
Già giàOriginariamente inviato da /dev/null
Ehm, "file:///home/post.txt" dubito che possa riferirsi a "F:\home"... Mi sembra tanto un path Unixiano che si riferisce a "/home/post.txt" che su window non ha molto senso :ignore:
Comunque cose simili non sara' mai possibile farle, se non sfruttando bug o in altri modi vietati qua sul forum.![]()
window.onload= function(){
try
{
loadUrl('file:///F:/home/post.txt');
}
catch(e){
alert(e);
}
}
Con questo codice (che funziona con IE e Opera)
FF doesn't work
ed è a synchronous request
Codice PHP:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="JavaScript" type="text/JavaScript">
var req = null;
function processReqChange() {
if(req.status == 0){
alert(req.responseText);
}
}
function loadUrl( url ) {
if(window.XMLHttpRequest) {
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) {
req.onreadystatechange = processReqChange;
req.open('GET', url, false);
req.send('');
}
}
window.onload= function(){
try
{
loadUrl('file:///F:/home/post.txt');
}
catch(e){
alert(e);
}
}
</script>
<body>
<h1>Walking the dog</h1>
<span id="moreSpan">
</span>
</body>
</html>
Per la cronaca con l'altro metodo
l'alert in FF scatta 5 volte tre volte
vuoto 2 con il risultato.
![]()
Without faith, nothing is possible. With it, nothing is impossible
http://ilwebdifabio.it
Ajax utilizza un oggetto che si chiama XMLHttpRequest ... se usi i file locali elimini Http e l'oggetto XMLRequest non mi risulta esista .... in soldoni Ajax in locale richiede un webserver, PAMPA è una delle N soluzioni possibili con tanto di PHP o altro, fuinziona da CD-ROM, DVD, SIM , USB o quello che vuoi e lo sviluppo ajax potrà essere effettivo![]()
funziona su ie opera e ffCodice PHP:file:///F:/Documents%20and%20Settings/whisher/Desktop/test.html
con
e ho chiuso ApacheCodice PHP:req.open('GET', url, false);
![]()
![]()
Without faith, nothing is possible. With it, nothing is impossible
http://ilwebdifabio.it
funziona ma non è Ajax ... facile ...
P.S. e su IE funziona solo se abiliti l'esecuzione dello script (non so se col condizionale va anche l'ActiveX) .. cosa che tramite webserver non ti serve ... in soldoni o ci dici l'obiettivo finale oppure è dura proseguire con il post