Ajax <-> PHP <-> XML Response <-> in einer Schleife....

Gehtt -> darf das nicht auf zwei Funktionen verteilen. Hab es nun in einer drin und geht.

Code:
	function loadViaAjax(ctr)
    {
        var XmlRequest;
        
        try
        {
            XmlRequest = new XMLHttpRequest();
        }
        catch (e)
        {
            try
            {
                XmlRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e)
            {
                try
                {
                    XmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } 
                catch (failed)
                {
                    XmlRequest = null;
                }
            }  
        }
        
        if(document.getElementById("info_tag").innerHTML != "")
            document.getElementById("info_tag").innerHTML += "<br>";
        document.getElementById("info_tag").innerHTML += '<strong>Loading: ' + ctr + '</strong>';        
        
        XmlRequest.onreadystatechange = function()
        {
            switch(XmlRequest.readyState)
            {
                case 4:
                    if(XmlRequest.status!=200) 
                    {
                        if(document.getElementById("info_tag").innerHTML != "")
                            document.getElementById("info_tag").innerHTML += "<br>";
                        document.getElementById("info_tag").innerHTML += '<strong>' + XmlRequest.status + '</strong>';
                    }
                    else
                    {                
                        if(document.getElementById("info_tag").innerHTML != "")
                            document.getElementById("info_tag").innerHTML += "<br>";
                        document.getElementById("info_tag").innerHTML += '<strong>' + XmlRequest.responseText + '</strong>';
                    }
                    break;
 
                default:
                    return false;
                break;
            }
        };
        
        var params = "?ctr="+ctr;
        XmlRequest.open("GET", "AjaxResponse.php"+params, true);
        XmlRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        XmlRequest.send(null);
    }
       
    function pageLoad()
    {
        for(i=0; i<10; i++)
        	loadViaAjax(i);
    }
 
Zurück