|
|
Ligne 1 : |
Ligne 1 : |
| function getXhr(){
| |
| var xhr = null;
| |
| if(window.XMLHttpRequest) // Firefox et autres
| |
| xhr = new XMLHttpRequest();
| |
| else if(window.ActiveXObject){ // Internet Explorer
| |
| try {
| |
| xhr = new ActiveXObject("Msxml2.XMLHTTP");
| |
| } catch (e) {
| |
| xhr = new ActiveXObject("Microsoft.XMLHTTP");
| |
| }
| |
| }
| |
| else { // XMLHttpRequest non supporté par le navigateur
| |
| alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
| |
| xhr = false;
| |
| }
| |
| return xhr;
| |
| }
| |
|
| |
| // Node cleaner
| |
| function go(c){
| |
| if(!c.data.replace(/\s/g,''))
| |
| c.parentNode.removeChild(c);
| |
| }
| |
|
| |
|
| function clean(d){
| |
| var bal=d.getElementsByTagName('*');
| |
|
| |
| for(i=0;i<bal.length;i++){
| |
| a=bal[i].previousSibling;
| |
| if(a && a.nodeType==3)
| |
| go(a);
| |
| b=bal[i].nextSibling;
| |
| if(b && b.nodeType==3)
| |
| go(b);
| |
| }
| |
| return d;
| |
| }
| |
|
| |
|
| |
| function goRSS(){
| |
| var xhr = getXhr();
| |
| // On défini ce qu'on va faire quand on aura la réponse
| |
| xhr.onreadystatechange = function(){
| |
| // On ne fait quelque chose que si on a tout reçu et que le serveur est ok
| |
| if(xhr.readyState == 4 && xhr.status == 200){
| |
| reponse = clean(xhr.responseXML.documentElement);
| |
| alert(reponse.getElementsByTagName("message")[0].firstChild.nodeValue);
| |
| }
| |
| }
| |
| xhr.open("GET","http://fr.guildwars.com/home/news.rss",true);
| |
| xhr.send(null);
| |
|
| |
| }
| |