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

    [Ajax] Una semplice classe ...

    Ciao.
    Codice PHP:
    //Inspired by: [url]http://creativecommons.org/licenses/by-sa/2.0/[/url]
    // and by Andr3a 
    function XHConn(){
        var 
    xmlhttp null;
        var 
    resulttrue;
        var 
    browser navigator.userAgent.toUpperCase();
        if(
    typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object"){
                
    xmlhttp = new XMLHttpRequest();
        }
        else if(
    window.ActiveXObject && browser.indexOf("MSIE 4") < 0){
            if(
    browser.indexOf("MSIE 5") < 0){
                
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
            else{
                
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
        }
        if (
    xmlhttp===null){resultfalse;}
        
    this.connect = function(sURLsMethodsVarsfnDonefnError){
            
    sMethod sMethod.toUpperCase();
            
    xmlhttp.open(sMethodsURLtrue);
            if (
    sMethod == "POST"){
                
    xmlhttp.setRequestHeader("Method""POST "+sURL+" HTTP/1.1");
                
    xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
                
    xmlhttp.setRequestHeader('Content-Length'sVars.length);
            }
            
    xmlhttp.onreadystatechange = function(){
                if (
    xmlhttp.readyState == 4){
                    if(
    xmlhttp.status == 200){
                        
    fnDone(xmlhttp);
                       }
                    else{
                           
    fnError(xmlhttp);
                    }
                }
            }
            
    xmlhttp.setRequestHeader("connection""close");
            
    xmlhttp.send(sVars);
        }
        return 
    result;
    }
    function 
    yourCallback(xhr) {
      
    alert(xhr.responseText);
    }
    function 
    errorHandler(xhr){
        
    alert("HTTP error: "+xhr.status);
    }
    xhr = new XHConn();
    xhr1 = new XHConn();
    xhr.connect('post.php''POST'"param=target_value"yourCallbackerrorHandler);
    xhr1.connect('get.htm''GET'""yourCallbackerrorHandler); 

    Critiche suggerimenti e miglioramenti sono molto benvenuti


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

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

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.