Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 20th, 2012  |  syntax: JavaScript  |  size: 2.61 KB  |  hits: 28  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2.  
  3.  
  4. <head>
  5.      <title>TerraXML Devices</title>
  6.  
  7.          <link href="css/smoothness/jquery-ui-1.8.23.custom.css" rel="stylesheet" type="text/css"/>
  8.      <script  type="text/javascript" src="jquery-1.7.2.min.js""></script>
  9.          <script  type="text/javascript" src="jquery-ui-1.8.23.custom.min.js"></script>
  10.      </script>
  11.  
  12.  
  13.         <script type="text/javascript">
  14.                 $(document).ready(function() {
  15.                         createDynamicTable($("#tbl"), 4, 16);
  16.                         updateTable();
  17.                         setInterval("updateTable()", 4000);
  18.                          
  19.                 });
  20.  
  21.                
  22.                
  23.         function updateTable() {
  24.        
  25.                 $.ajax({
  26.                         type: "GET",
  27.                         url: "xml_parser.exe",
  28.                         ifModified:true,
  29.                         dataType: "xml",
  30.                                 statusCode: {
  31.                                 404: function() {
  32.                                         console.log('Page not found');
  33.                                         return;
  34.                                         }
  35.                                 },
  36.                         success: function(xml, status) {
  37.                                 if (status != 'success') {
  38.                                         return;
  39.                                 }
  40.                                
  41.                                 $("#tbl td.tableCell").each(function() {
  42.                                         var found_dev = 0;
  43.                                         var id = $(this).attr('id');
  44.                                         $(xml).find('dev').each(function(){
  45.                                                 var log = '';
  46.                                                 var diag = '';
  47.                                                 var error = '';
  48.                                                 var address = $(this).attr('id');
  49.                                                 var status = $(this).attr('status');
  50.                                                 console
  51.                                                 if (status & 0x01) {
  52.                                                         log = '(D)';
  53.                                                 }
  54.                                                 if (status & 0x02) {
  55.                                                         log = '(L)';
  56.                                                 }
  57.                                                 if (status & 0x08) {
  58.                                                         log = '(E)';
  59.                                                 }
  60.                                                 var title = $(this).attr('title');
  61.                                                 if (id == address) {
  62.                                                         if (status != 0) {
  63.                                                                 $("#tbl td.tableCell")
  64.                                                                 $("#"+address).html('<button><a href=\"device.html?dev=' + address + '\">' + title + ' ' + error + diag + log + '</a></button>');
  65.                                                                 found_dev = 1;
  66.                                                         }
  67.                                                 }
  68.                                         });
  69.                                         if (!found_dev) {
  70.                                                 $("#tbl td.tableCell")
  71.                                                         $("#"+id).html("---");
  72.                                         }
  73.                                 });
  74.                         },
  75.                         error: function(res, stat) {
  76.                                 console.log('non success'+ res+stat);
  77.                                 }
  78.                 });
  79.         }      
  80.                
  81.      function createDynamicTable(tbody, rows, cols) {
  82.          if (tbody == null || tbody.length < 1) return;
  83.          for (var r = 0; r < rows; r++) {
  84.              var trow = $("<tr>");
  85.              for (var c = 0; c < cols; c++) {
  86.                  var cellText = 16 * r + c;
  87.                                  var blah = $("<td id=" + cellText +">")
  88.                          .addClass("tableCell")
  89.                          .text(cellText)
  90.                          .appendTo(trow);
  91.                                  
  92.  
  93.              }
  94.              trow.appendTo(tbody);
  95.          }
  96.      }  
  97.          
  98.  
  99.       </script>
  100.  
  101.  
  102.  </head>
  103.  
  104.  
  105.  <body>
  106.         <div id="page-wrap">
  107.        
  108.     </div>
  109.          
  110.        
  111.      <table id="tbl" border="1">
  112.          <tbody>
  113.          </tbody>
  114.      </table>
  115. </body>
  116. </html>