Simplifier une fonction javascript

WRInaute impliqué
Bonjour,

J'aimerais savoir si c'est possible de simplifier cette fonction javascript qui comporte 2 ensembles similaire :

Code:
function refresh() 
{
var xhr = getXMLHttpRequest();
var xhr2 = getXMLHttpRequest();
xhr.onreadystatechange = function() {
		
        if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
                document.getElementById('babble').innerHTML = xhr.responseText;
        }
};
 
xhr.open("GET", "?do=babble", true);
xhr.send(null);

xhr2.onreadystatechange = function() {
		
        if (xhr2.readyState == 4 && (xhr2.status == 200 || xhr2.status == 0)) {
                document.getElementById('map').innerHTML = xhr2.responseText;
        }
};
 
xhr2.open("GET", "?do=map", true);
xhr2.send(null);

setTimeout("refresh()", 2500);
}

Merci
 
WRInaute accro
Code:
function refresh_one(what)
{
        var xhr = getXMLHttpRequest();
        xhr.onreadystatechange = function()
        {
                if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0))
                {
                        document.getElementById(what).innerHTML = xhr.responseText;
                }
        };

        xhr.open("GET", "?do="+what, true);
        xhr.send(null);
}

function refresh()
{
        refresh_one('babble');
        refresh_one('map');

        setTimeout("refresh()", 2500);
}

Non?

Jacques.
 
Discussions similaires
Haut