Funzione Javascript per AJAX

function richiesta_AJAX(pagina,parametri,ritorno){
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    } else {
        // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            if (typeof ritorno === "function") {
                ritorno(this.responseText);
            }
        }
    }
    xmlhttp.open("POST",pagina,true);
    //Send the proper header information along with the request
    xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    xmlhttp.send(parametri);
}

Leave a Reply