Advertisement
Guest User

Untitled

a guest
May 27th, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!doctype html>
  2. <html>
  3. <head>
  4.     <meta charset="utf-8" />
  5.     <title>Dico 1</title>
  6.     <style>
  7.         body{
  8.             width: 1000px;
  9.             text-align: center;
  10.         }
  11.         form{
  12.             width: 400px;
  13.             margin-top: 80px;
  14.             margin-left: 480px;
  15.         }
  16.         fieldset{
  17.             border: 1px solid lightblue;
  18.         }
  19.         div{
  20.             width: 600px;
  21.             margin-top: 80px;
  22.             margin-left: 370px;
  23.         }
  24.  
  25.     </style>
  26.     <script>
  27.         //Vérification / Connexion au serveur
  28.         function createXMLHTTP() {
  29.             var httpRequest = false;
  30.             if (window.XMLHttpRequest) {    // Mozilla, Safari,...
  31.                 httpRequest = new XMLHttpRequest();
  32.                 if (httpRequest.overrideMimeType) {
  33.                     httpRequest.overrideMimeType('text/xml');
  34.                 }
  35.             } else if (window.ActiveXObject) { // IE
  36.                 try {
  37.                     httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
  38.                 } catch (e) {
  39.                     try {
  40.                         httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
  41.                     } catch (e) {}
  42.                 }
  43.             }
  44.  
  45.             if (!httpRequest) {
  46.                 alert('Désolé ! :( Impossible de créer une instance XMLHTTP');
  47.                 return false;
  48.             }
  49.             return httpRequest;
  50.         }
  51.         //Interaction avec le fichier Méthode POST
  52.         function makeRequest(file, div) {
  53.             if(httpRequest = createXMLHTTP()) {
  54.                 httpRequest.onreadystatechange = function() { afficher(httpRequest, div); };
  55.                 httpRequest.open('POST', file, true);
  56.                 httpRequest.send("tri?up");
  57.             }
  58.         }
  59.         //Fonction d'afficage, Traitement du DHTML
  60.         function afficher(httpRequest, div) {
  61.             if (httpRequest.readyState == 4) {
  62.                 if (httpRequest.status == 200) {
  63.                     var contenu = "Traitement";
  64.                     var tabKeys = new Array(); //Contient les clés -> th
  65.                     var tabMots = new Array(); //Contient les Mots XML
  66.                     var tabWords = new Array(); //Contient les mots -> td
  67.                     var xmldoc = httpRequest.responseXML;
  68.                     var file_mot = xmldoc.getElementsByTagName('mot');
  69.  
  70.                     for(var i=0; i<file_mot.length; i++){
  71.                         if(file_mot[i].attributes.length === 2 ){
  72.                             if(file_mot[i].attributes[0].value !== 'nature'){
  73.                                 if(file_mot[i].attributes[1].value === 'important'){
  74.                                     tabMots.push(file_mot[i]);
  75.                                 }
  76.                             }
  77.  
  78.                         }
  79.  
  80.                     }
  81.                    
  82.                     contenu += "<table><tr>";
  83.                     for(var i=0; i<tabMots.length; i++){
  84.                         if(tabKeys.indexOf(tabMots[i].attributes[0].value) === -1){
  85.                             tabKeys.push(tabMots[i].attributes[0].value);
  86.                             contenu +="<th>"+tabMots[i].attributes[0].value+"</th>";
  87.  
  88.                         }
  89.                     }
  90.                     contenu += "</tr>";
  91.  
  92.  
  93.                  
  94.  
  95.                 } else {
  96.                     document.getElementById(div).innerHTML = '¨Problème avec la requête.';
  97.                 }
  98.             }
  99.             document.getElementById(div).innerHTML = contenu;
  100.         }
  101.  
  102.     </script>
  103. </head>
  104. <body onload="makeRequest('dico2.xml','affichage')">
  105.  
  106.     <div id="affichage" style="border:1px solid yellow; background-color:lightblue;">
  107.  
  108.     </div>
  109. </body>
  110. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement