Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 11
  1. #1

    [AJAX] with non http protocol .....

    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

  2. #2
    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
    Formaldehyde a new Ajax PHP Zero Config Error Debugger

    WebReflection @WebReflection

  3. #3
    Ho trovato il tutto qui

    Per curiosità ho fatto una prova (primo codice che
    mi è venuto alla mano )

    Codice PHP:
    <script language="JavaScript" type="text/JavaScript">

    var 
    req null;
    function 
    processReqChange() { 
     if(
    req.status == 0
      
    alert(req.responseText);
    }
    function 
    loadUrlurl ) {
      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'urltrue);
        
    req.send('');
      }
    }

    window.onload= function(){

    loadUrl('file:///home/post.txt');
    }
    </script> 
    ma FF dice
    Access to 'file:///home/post.txt' from script denied
    Il file l'ho messo in F:\home
    mi pesco qc ?


    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  4. #4
    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

    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.
    ma non è un bug .. è stra normale che sia così ... ma che stanno facendo in MDC? :master:


    [edit]
    ah ... ok, era il tipo del bug che non ha capito molto di HTTP
    It'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://.
    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 serve
    Formaldehyde a new Ajax PHP Zero Config Error Debugger

    WebReflection @WebReflection

  5. #5
    Thanks

    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  6. #6
    Utente di HTML.it L'avatar di /dev/null
    Registrato dal
    May 2004
    Messaggi
    1,936
    Originariamente inviato da whisher
    Codice PHP:
    loadUrl('file:///home/post.txt'); 
    Il file l'ho messo in F:\home
    mi pesco qc ?
    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.
    Ultima modifica ad opera dell'utente /dev/null il 01-01-0001 alle 00:00

  7. #7
    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.
    Già già

    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 
    loadUrlurl ) {
      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'urlfalse);
        
    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

  8. #8
    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
    Formaldehyde a new Ajax PHP Zero Config Error Debugger

    WebReflection @WebReflection

  9. #9
    Codice PHP:
    file:///F:/Documents%20and%20Settings/whisher/Desktop/test.html 
    funziona su ie opera e ff

    con

    Codice PHP:
      req.open('GET'urlfalse); 
    e ho chiuso Apache


    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  10. #10
    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
    Formaldehyde a new Ajax PHP Zero Config Error Debugger

    WebReflection @WebReflection

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.