Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8" />
- <title>Dico 1</title>
- <style>
- body{
- width: 1000px;
- text-align: center;
- }
- form{
- width: 400px;
- margin-top: 80px;
- margin-left: 480px;
- }
- fieldset{
- border: 1px solid lightblue;
- }
- div{
- width: 600px;
- margin-top: 80px;
- margin-left: 370px;
- }
- </style>
- <script>
- //Vérification / Connexion au serveur
- function createXMLHTTP() {
- var httpRequest = false;
- if (window.XMLHttpRequest) { // Mozilla, Safari,...
- httpRequest = new XMLHttpRequest();
- if (httpRequest.overrideMimeType) {
- httpRequest.overrideMimeType('text/xml');
- }
- } else if (window.ActiveXObject) { // IE
- try {
- httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
- } catch (e) {
- try {
- httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
- } catch (e) {}
- }
- }
- if (!httpRequest) {
- alert('Désolé ! :( Impossible de créer une instance XMLHTTP');
- return false;
- }
- return httpRequest;
- }
- //Interaction avec le fichier Méthode POST
- function makeRequest(file, div) {
- if(httpRequest = createXMLHTTP()) {
- httpRequest.onreadystatechange = function() { afficher(httpRequest, div); };
- httpRequest.open('POST', file, true);
- httpRequest.send("tri?up");
- }
- }
- //Fonction d'afficage, Traitement du DHTML
- function afficher(httpRequest, div) {
- if (httpRequest.readyState == 4) {
- if (httpRequest.status == 200) {
- var contenu = "Traitement";
- var tabKeys = new Array(); //Contient les clés -> th
- var tabMots = new Array(); //Contient les Mots XML
- var tabWords = new Array(); //Contient les mots -> td
- var xmldoc = httpRequest.responseXML;
- var file_mot = xmldoc.getElementsByTagName('mot');
- for(var i=0; i<file_mot.length; i++){
- if(file_mot[i].attributes.length === 2 ){
- if(file_mot[i].attributes[0].value !== 'nature'){
- if(file_mot[i].attributes[1].value === 'important'){
- tabMots.push(file_mot[i]);
- }
- }
- }
- }
- contenu += "<table><tr>";
- for(var i=0; i<tabMots.length; i++){
- if(tabKeys.indexOf(tabMots[i].attributes[0].value) === -1){
- tabKeys.push(tabMots[i].attributes[0].value);
- contenu +="<th>"+tabMots[i].attributes[0].value+"</th>";
- }
- }
- contenu += "</tr>";
- } else {
- document.getElementById(div).innerHTML = '¨Problème avec la requête.';
- }
- }
- document.getElementById(div).innerHTML = contenu;
- }
- </script>
- </head>
- <body onload="makeRequest('dico2.xml','affichage')">
- <div id="affichage" style="border:1px solid yellow; background-color:lightblue;">
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement