Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    [ajax - javascript] problema con parametri get e IE8

    Salve a tutti...io sto creando una pagina in html che grazie a javascript e ajax che se non ha un parametro ?name nell'url (esempio: index.htm?nome=vacanze) carica il file tabella.php (che se non riceve nessun nome restituisce la lista di nomi)... invece se ha un nome carica sempre il file php ma inviando il parametro nome (per esempio tabella.php?nome=vacanze)... ottenendo come risultato una tabella con delle immagini...
    ho provato a farlo cosi documentandomi in internet (sono un novizio in ajax):

    Codice PHP:
    <!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">
    <
    head>
        <
    meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
        <
    meta name="generator" content="" />
        <
    link href="stile.css" rel="stylesheet" type="text/css" />
        <
    script type="text/javascript" src="utility.js"></script>
        <script type="text/javascript" language="JavaScript">
            <!--hide
            var folder;
            var file;
            
    function prendiElementoDaId(id_elemento) {
                var elemento;
                if(document.getElementById)
                    elemento = document.getElementById(id_elemento);
                else
                    elemento = document.all[id_elemento];
                return elemento;
            };
        
        // funzione per assegnare un oggetto XMLHttpRequest
            function assegnaXMLHttpRequest() {
                var
                    XHR = null,
                    browserUtente = navigator.userAgent.toUpperCase();
                if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
                    XHR = new XMLHttpRequest();
                else if(window.ActiveXObject && browserUtente.indexOf("MSIE 4") < 0) {
                    if(browserUtente.indexOf("MSIE 5") < 0)
                        XHR = new ActiveXObject("Msxml2.XMLHTTP");
                    else
                        XHR = new ActiveXObject("Microsoft.XMLHTTP");
                }
                return XHR;
            };



        // oggetto di verifica stato
            var readyState = {
                INATTIVO:    0,
                INIZIALIZZATO:    1,
                RICHIESTA:    2,
                RISPOSTA:    3,
                COMPLETATO:    4
            };

        // array descrittivo dei codici restituiti dal server
        // [la scelta dell' array è per evitare problemi con vecchi browsers]
            var statusText = new Array();
            statusText[100] = "Continue";
            statusText[101] = "Switching Protocols";
            statusText[200] = "OK";

            function cambia(num){
                var namet='t'+num;
                var namel='l'+num;
                if (document.all[namet].style.display=="none") {
                    prendiElementoDaId('t'+num).value=prendiElementoDaId('c'+num).value;
                    document.all[namet].style.display = "";
                    document.all[namel].style.display = "none";
                    document.all['post'+num].style.display = "";
                    prendiElementoDaId('submit'+num).setAttribute("value","Annulla");
                }
                else {
                    document.all[namel].style.display = "";
                    document.all[namet].style.display = "none";
                    document.all['post'+num].style.display = "none";
                    prendiElementoDaId('t'+num).value=prendiElementoDaId('c'+num).value;
                    prendiElementoDaId('submit'+num).setAttribute("value","Rinomina");
                }
            }
            
            function getFolder(){
                var param = window.location.search.substr(1).split(/\&/);
                for(var i=0; i<param.length; i++) {
                    var nom_val = param[i].split(/\=/);
                    if (nom_val[0]=='nome'){
                        folder=unescape(nom_val[1]);
                    }
                    else if (nom_val[0]=='file'){
                        file=unescape(nom_val[1]);
                    }
                }    
            }
            
            function caricatabella(){
                var ajax = assegnaXMLHttpRequest();
                var    elemento = prendiElementoDaId('erase');
                var usaLink = true;  
                getFolder()
                if (file!=undefined){
                      //elimina(file);
                }
                if(ajax) {
                    var link="tabella.php";
                    var nomeFile="";
                    if (folder!=undefined){
                          nomeFile += "?nome=" + escape(folder);
                    }
                    alert(nomeFile);
                    usaLink = false;
                    elemento.innerHTML="<p Style=\"text-align:center\">Attendere prego</p>";
                    ajax.open("POST", link+nomeFile, true);
                    ajax.setRequestHeader("connection", "close");
                    ajax.onreadystatechange = function() {
                        if(ajax.readyState === readyState.COMPLETATO) {
                            if(statusText[ajax.status] === "OK")
                                elemento.innerHTML = ajax.responseText;
                            else {
                                elemento.innerHTML = "Impossibile effettuare l'operazione richiesta.
    ";
                                elemento.innerHTML += "Errore riscontrato: " + statusText[ajax.status];
                            }
                        }
                    }
                    ajax.send(null);
                }
                return usaLink;
            }
            //-->
        </script>

    </head>
    <body onload="javascript:caricatabella()">
                    <div id="erase">
                    </div>
    </body>
    </html> 
    l'ho provato in firefox e funziona perfettamente...vengono inviati i parametri e il risultato è corretto...
    ma se provo a utilizzarlo in internet explorer non funziona! cioè finche richiedo la pagina tabella.php funziona perfettamente...ma quando invio tabella.php?nome=qualcosa la pagina php non riceve niente in ritorno! come è possibile?

  2. #2
    scusate l'errore.. ma ho postato una vecchia versionenon corretta e che non
    funzionava...

    questa è la versione giusta:

    <!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">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <meta name="generator" content="" />
    <title>La protezione civile </title>
    <link href="stile.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="utility.js"><!--// ajax utility
    //--></script>
    <script type="text/javascript" language="JavaScript">
    <!--hide
    var folder;
    var file;
    var renamed=true;
    var ajax;

    // funzione per prendere un elemento con id univoco
    function prendiElementoDaId(id_elemento) {
    var elemento;
    if(document.getElementById)
    elemento = document.getElementById(id_elemento);
    else
    elemento = document.all[id_elemento];
    return elemento;
    };

    // funzione per assegnare un oggetto XMLHttpRequest
    function assegnaXMLHttpRequest() {
    var
    XHR = null,
    browserUtente = navigator.userAgent.toUpperCase();
    if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) ===
    "object")
    XHR = new XMLHttpRequest();
    else if(window.ActiveXObject && browserUtente.indexOf("MSIE 4") < 0) {
    if(browserUtente.indexOf("MSIE 5") < 0)
    XHR = new ActiveXObject("Msxml2.XMLHTTP");
    else
    XHR = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return XHR;
    };



    /** OGGETTI / ARRAY */

    // oggetto di verifica stato
    var readyState = {
    INATTIVO: 0,
    INIZIALIZZATO: 1,
    RICHIESTA: 2,
    RISPOSTA: 3,
    COMPLETATO: 4
    };

    // array descrittivo dei codici restituiti dal server
    // [la scelta dell' array è per evitare problemi con vecchi browsers]
    var statusText = new Array();
    statusText[100] = "Continue";
    statusText[101] = "Switching Protocols";
    statusText[200] = "OK";
    statusText[201] = "Created";
    statusText[202] = "Accepted";
    statusText[203] = "Non-Authoritative Information";
    statusText[204] = "No Content";
    statusText[205] = "Reset Content";
    statusText[206] = "Partial Content";
    statusText[300] = "Multiple Choices";
    statusText[301] = "Moved Permanently";
    statusText[302] = "Found";
    statusText[303] = "See Other";
    statusText[304] = "Not Modified";
    statusText[305] = "Use Proxy";
    statusText[306] = "(unused, but reserved)";
    statusText[307] = "Temporary Redirect";
    statusText[400] = "Bad Request";
    statusText[401] = "Unauthorized";
    statusText[402] = "Payment Required";
    statusText[403] = "Forbidden";
    statusText[404] = "Not Found";
    statusText[405] = "Method Not Allowed";
    statusText[406] = "Not Acceptable";
    statusText[407] = "Proxy Authentication Required";
    statusText[408] = "Request Timeout";
    statusText[409] = "Conflict";
    statusText[410] = "Gone";
    statusText[411] = "Length Required";
    statusText[412] = "Precondition Failed";
    statusText[413] = "Request Entity Too Large";
    statusText[414] = "Request-URI Too Long";
    statusText[415] = "Unsupported Media Type";
    statusText[416] = "Requested Range Not Satisfiable";
    statusText[417] = "Expectation Failed";
    statusText[500] = "Internal Server Error";
    statusText[501] = "Not Implemented";
    statusText[502] = "Bad Gateway";
    statusText[503] = "Service Unavailable";
    statusText[504] = "Gateway Timeout";
    statusText[505] = "HTTP Version Not Supported";
    statusText[509] = "Bandwidth Limit Exceeded";

    function cambia(num){
    var namet='t'+num;
    var namel='l'+num;
    if (prendiElementoDaId(namet).style.display=="none") {
    prendiElementoDaId('t'+num).value=prendiElementoDa Id('c'+num).value;
    prendiElementoDaId(namet).style.display = "";
    prendiElementoDaId(namel).style.display = "none";
    prendiElementoDaId('post'+num).style.display = "";

    prendiElementoDaId('submit'+num).setAttribute("val ue","Annulla");
    }
    else {
    prendiElementoDaId(namel).style.display = "";
    prendiElementoDaId(namet).style.display = "none";
    prendiElementoDaId('post'+num).style.display = "none";
    prendiElementoDaId('t'+num).value=prendiElementoDa Id('c'+num).value;

    prendiElementoDaId('submit'+num).setAttribute("val ue","Rinomina");
    }
    }

    function controlla(){
    var check=false;
    var con=1;
    while (prendiElementoDaId("c"+con) != null){
    if (prendiElementoDaId("c"+con).checked==true){
    check=true;
    break;
    }
    con++;
    }
    return check;
    }

    function cambia(num){
    var namet='t'+num;
    var namel='l'+num;
    if (prendiElementoDaId(namet).style.display=="none") {
    prendiElementoDaId('t'+num).value=prendiElementoDa Id('c'+num).value;
    prendiElementoDaId(namet).style.display = "";
    prendiElementoDaId(namel).style.display = "none";
    prendiElementoDaId('post'+num).style.display = "";

    prendiElementoDaId('submit'+num).setAttribute("val ue","Annulla");
    }
    else {
    prendiElementoDaId(namel).style.display = "";
    prendiElementoDaId(namet).style.display = "none";
    prendiElementoDaId('post'+num).style.display = "none";
    prendiElementoDaId('t'+num).value=prendiElementoDa Id('c'+num).value;

    prendiElementoDaId('submit'+num).setAttribute("val ue","Rinomina");
    }
    }

    function getFolder(){
    var param = window.location.search.substr(1).split(/\&/);
    for(var i=0; i<param.length; i++) {
    var nom_val = param[i].split(/\=/);
    if (nom_val[0]=='nome'){
    folder=unescape(nom_val[1]);
    }
    else if (nom_val[0]=='file'){
    file=unescape(nom_val[1]);
    }
    }
    }

    function caricatabella(){
    ajax = assegnaXMLHttpRequest();
    var elemento = prendiElementoDaId('erase');
    var usaLink = true;
    getFolder()
    if (file!=undefined){
    //elimina(file);
    }
    if(ajax) {
    var link="tabella.php";
    var nomeFile="";
    if (folder!=undefined){
    nomeFile += "?nome=" + escape(folder);
    }
    usaLink = false;
    elemento.innerHTML="<p Style=\"text-align:center\">Attendere prego</p>";
    ajax.open("GET", link+nomeFile, true);
    ajax.setRequestHeader("connection", "close");
    ajax.onreadystatechange = function() {
    if(ajax.readyState === readyState.COMPLETATO) {
    if(statusText[ajax.status] === "OK")
    elemento.innerHTML = ajax.responseText;
    else {
    elemento.innerHTML = "Impossibile effettuare l'operazione
    richiesta.
    ";
    elemento.innerHTML += "Errore riscontrato: " + statusText[ajax.status];
    }
    }
    }
    ajax.send(null);
    }
    return usaLink;
    }


    //-->
    </script>

    </head>
    <body onload="caricatabella()">
    <div id="erase">
    </div>
    </body>
    </html>

    potete anche verificare che va su firefox e non su ie da qui:
    http://allfromtheworld.altervista.org/gestione.php
    che funziona
    e da qui:
    http://allfromtheworld.altervista.or....php?nome=ciao
    che non funziona...
    il problema non è del php perche se vado ad aprire
    http://allfromtheworld.altervista.or....php?nome=ciao
    funziona...quale può essere il problema?

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.