Visualizzazione dei risultati da 1 a 4 su 4

Discussione: ajax

  1. #1
    Utente di HTML.it
    Registrato dal
    Sep 2006
    Messaggi
    36

    ajax

    ciao a tutti, per favore aiutatemi perchè non ho idea di come risolvere questo inconveniente.
    in pratica ho creato uno script per la richiesta tramite ajax di apertura di una pagina php (che fa una query sul mio db), il problema è che su firefox funge alla grande ma solo di ie mi da errore di run-time sconosciuto
    ecco il codice
    codice:
    function createRequestObject(){
    
    var req;
    
    if(window.XMLHttpRequest){
    //For Firefox, Safari, Opera
    req = new XMLHttpRequest();
    }
    else if(window.ActiveXObject){
    //For IE 5+
    req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else{
    //Error for an old browser
    alert('Your browser is not IE 5 or higher, or Firefox or Safari or Opera');
    }
    
    return req;
    }
    
    //Make the XMLHttpRequest Object
    var http = createRequestObject();
    
    function sendRequest(nomediv) {
    http.open('GET','elenco_fornitori.php',true);
    http.onreadystatechange = function() {handleResponse(nomediv);};
    http.send(null);
    }
    
    function handleResponse(nomediv){
    if (http.readyState == 4) {
    if (http.status == 200) {
        document.getElementById(nomediv).style.display='block';
        document.getElementById(nomediv).innerHTML=http.responseText;
    }
    else {
        document.getElementById(nomediv).style.display='block';
        document.getElementById(nomediv).innerHTML="ERRORE "+http.status;
    }
    }
    }
    la richiesta la faccio cosi
    <a href="#" onclick="sendRequest('prova.php','mio_div');">

  2. #2
    codice:
    function sendRequest(nomediv)
    vedo che accetta un solo parametro e te ne passi 2

    codice:
    <a href="#" onclick="sendRequest('prova.php','mio_div');">
    http://www.anobii.com/isalreadyinuse

  3. #3
    Utente di HTML.it
    Registrato dal
    Sep 2006
    Messaggi
    36
    in effetti ho sbagliato a copiare!
    function createRequestObject(){

    var req;

    if(window.XMLHttpRequest){
    //For Firefox, Safari, Opera
    req = new XMLHttpRequest();
    }
    else if(window.ActiveXObject){
    //For IE 5+
    req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else{
    //Error for an old browser
    alert('Your browser is not IE 5 or higher, or Firefox or Safari or Opera');
    }

    return req;
    }

    //Make the XMLHttpRequest Object
    var http = createRequestObject();

    function sendRequest(url,nomediv) {
    http.open('GET',url,true);
    http.onreadystatechange = function() {handleResponse(nomediv);};
    http.send(null);
    }

    function handleResponse(nomediv){
    if (http.readyState == 4) {
    if (http.status == 200) {
    document.getElementById(nomediv).style.display='bl ock';
    document.getElementById(nomediv).innerHTML=http.re sponseText;
    }
    else {
    document.getElementById(nomediv).style.display='bl ock';
    document.getElementById(nomediv).innerHTML="ERRORE "+http.status;
    }
    }
    }

  4. #4
    Moderatore di JavaScript L'avatar di br1
    Registrato dal
    Jul 1999
    Messaggi
    19,998
    Per cortesia, titoli esplicativi del problema... a norma di regolamento.

    Puoi aprire una nuova discussione
    Il guaio per i poveri computers e' che sono gli uomini a comandarli.

    Attenzione ai titoli delle discussioni: (ri)leggete il regolamento
    Consultate la discussione in rilievo: script / discussioni utili
    Usate la funzione di Ricerca del Forum

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.