Visualizzazione dei risultati da 1 a 7 su 7

Discussione: Caricare txt in un div

  1. #1
    Utente di HTML.it
    Registrato dal
    Sep 2002
    Messaggi
    477

    Caricare txt in un div

    E' tutto il giorno che cerco in rete e sul forum ma non sono riuscito a trovare ciò che mi serve....il fatto è che non conosco nulla di JS quindi quel poco che ho trovato non sono riuscito ad applicarlo.

    Sto facendo un sito in html\css e dovrei creare delle pagine che, alla loro apertura, carichino del testo da un file txt all'interno di un div. Qualcuno può aiutarmi?

    Grazie

  2. #2
    Ti consiglio di Usare PHP

  3. #3

    ..........

    Ciao.
    Sono d'accordo con Anony89
    ma vedi (la cosa non mi sembra avere
    molto senso ma ...........) tu se questo
    snippet di + aiutare con AJAX (torno
    a ripetere senza dinamicità cs ......).

    Codice PHP:
    <!--
        
    This is the source file for the "Hello World of AJAX" tutorial
        
        You may 
    use this code in your own projects as long as this 
        copyright is left    in place
    .  All code is provided AS-IS.
        
    This code is distributed in the hope that it will be useful,
         
    but WITHOUT ANY WARRANTYwithout even the implied warranty of
         MERCHANTABILITY 
    or FITNESS FOR A PARTICULAR PURPOSE.
        
        
    Please visit [url]http://www.DynamicAJAX.com[/url] for more great AJAX
        
    source code and tutorials.
        
        
    Copyright 2006 Ryan Smith 345 Technical 345 Group.
    -->
    <
    html>
        <
    head>
            <
    title>The Hello World of AJAX</title>
            <
    script language="JavaScript" type="text/javascript">
                
    //Gets the browser specific XmlHttpRequest Object
                
    function getXmlHttpRequestObject() {
                    if (
    window.XMLHttpRequest) {
                        return new 
    XMLHttpRequest(); //Not IE
                    
    } else if(window.ActiveXObject) {
                        return new 
    ActiveXObject("Microsoft.XMLHTTP"); //IE
                    
    } else {
                        
    //Display your error message here. 
                        //and inform the user they might want to upgrade
                        //their browser.
                        
    alert("Your browser doesn't support the XmlHttpRequest object.  Better upgrade to Firefox.");
                    }
                }            
                
    //Get our browser specific XmlHttpRequest object.
                
    var receiveReq getXmlHttpRequestObject();        
                
    //Initiate the asyncronous request.
                
    function sayHello() {
                    
    //If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
                    
    if (receiveReq.readyState == || receiveReq.readyState == 0) {
                        
    //Setup the connection as a GET call to SayHello.html.
                        //True explicity sets the request to asyncronous (default).
                        
                        //QUI DEVI METTERE IL TUO FILE DI TESTO

                        
    receiveReq.open('GET''SayHello.txt'true);
                        
    //Set the function that will be called when the XmlHttpRequest objects state changes.
                        
    receiveReq.onreadystatechange handleSayHello
                        
    //Make the actual request.

                        
    receiveReq.send(null);

                    }            
                }
                
    //Called every time our XmlHttpRequest objects state changes.
                
    function handleSayHello() {
                    
    //Check to see if the XmlHttpRequests state is finished.
                    
    if (receiveReq.readyState == 4) {
                        
    //Set the contents of our span element to the result of the asyncronous call.
                        
    document.getElementById('mydiv').innerHTML receiveReq.responseText;
                    }
                }
    window.onload = function()
    {
        
    sayHello();
    }
                
    </script>
        </head>
        <body>
            <div id="mydiv"></div>
        </body>
    </html> 
    naturalmente il file SayHello.txt

    hello, world
    un classico

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

  4. #4
    Utente di HTML.it
    Registrato dal
    Sep 2002
    Messaggi
    477
    Grazie whisher, ad una prima prova sembra fare al caso mio...non capisco però perchè dovrei usare php, c'è qualche 'controindicazione' utilizzando questo script?

  5. #5

    ......

    Ciao.
    c'è qualche 'controindicazione' utilizzando questo script?
    Penso di no l'unica cosa che ha poco
    senso almeno se non spieghi quello che vuoi
    fare.


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

  6. #6
    Utente di HTML.it
    Registrato dal
    Sep 2002
    Messaggi
    477
    L'unica cosa è che dovrei aggiornare i txt manualmente....ma non è un grosso problema.
    Ho provato lo script e funziona alla perfezione.

    Grazie ancora.

  7. #7
    Utente di HTML.it
    Registrato dal
    Oct 2006
    Messaggi
    21
    Originariamente inviato da Anony89
    Ti consiglio di Usare PHP
    io ho un problema analogo a quello di cui si discute qui! mi piacerebbe usare il php come consiglia Antony! qualcuno mi può passare un link in cui si spieghi come fare? in particolare io devo costruire un form con pulsanti all'interno di un div! ... o meglio... forse posso fare a meno del div che usavo per l'istruzione getElementById combinato con AJAX... insomma... se continuo vado OT...

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 © 2025 vBulletin Solutions, Inc. All rights reserved.