Witam,

Mam pewien problem z którym probowałem się uporac i siedze nad tym juz ponad tydzien i jakos nie moge dojsc do ladu i skladu..
Mianowicie mam karte przekaznikow ktora jest obslugiwana takim kodem:
  1. var timeOutMS = 5000; //ms
  2.  
  3. /**
  4. * Stores a queue of AJAX events to process
  5. */
  6. var ajaxList = new Array();
  7.  
  8. /**
  9. * Initiates a new AJAX command
  10. *
  11. * @param the url to access
  12. * @param the document ID to fill, or a function to call with response XML (optional)
  13. * @param true to repeat this call indefinitely (optional)
  14. * @param a URL encoded string to be submitted as POST data (optional)
  15. */
  16. function newAJAXCommand(url, container, repeat,time, data)
  17. {
  18. // Set up our object
  19. var newAjax = new Object();
  20. var theTimer = new Date();
  21. newAjax.url = url;
  22. newAjax.container = container;
  23. newAjax.repeat = repeat;
  24. newAjax.ajaxReq = null;
  25. newAjax.RepeatTime=time;
  26.  
  27. // Create and send the request
  28. if(window.XMLHttpRequest) {
  29. newAjax.ajaxReq = new XMLHttpRequest();
  30. newAjax.ajaxReq.open((data==null)?"GET":"POST", newAjax.url, true);
  31. newAjax.ajaxReq.send(data);
  32. // If we're using IE6 style (maybe 5.5 compatible too)
  33. } else if(window.ActiveXObject) {
  34. newAjax.ajaxReq = new ActiveXObject("Microsoft.XMLHTTP");
  35. if(newAjax.ajaxReq) {
  36. newAjax.ajaxReq.open((data==null)?"GET":"POST", newAjax.url, true);
  37. newAjax.ajaxReq.send(data);
  38. }
  39. }
  40.  
  41. newAjax.lastCalled = theTimer.getTime();
  42.  
  43. // Store in our array
  44. ajaxList.push(newAjax);
  45. }
  46.  
  47. /**
  48. * Loops over all pending AJAX events to determine
  49. * if any action is required
  50. */
  51. function pollAJAX() {
  52.  
  53. var curAjax = new Object();
  54. var theTimer = new Date();
  55. var elapsed;
  56. // Read off the ajaxList objects one by one
  57. for(i = ajaxList.length; i > 0; i--)
  58. {
  59. curAjax = ajaxList.shift();
  60. if(!curAjax)
  61. continue;
  62. elapsed = theTimer.getTime() - curAjax.lastCalled;
  63. // If we suceeded
  64. if(curAjax.ajaxReq.readyState == 4 && curAjax.ajaxReq.status == 200) {
  65. // If it has a container, write the result
  66. if(typeof(curAjax.container) == 'function'){
  67. curAjax.container(curAjax.ajaxReq.responseXML.documentElement);
  68. } else if(typeof(curAjax.container) == 'string') {
  69. document.getElementById(curAjax.container).innerHTML = curAjax.ajaxReq.responseText;
  70. } // (otherwise do nothing for null values)
  71.  
  72. curAjax.ajaxReq.abort();
  73. curAjax.ajaxReq = null;
  74.  
  75. // If it's a repeatable request, then do so
  76. if(curAjax.repeat)
  77. newAJAXCommand(curAjax.url, curAjax.container, curAjax.repeat,curAjax.RepeatTime);
  78. continue;
  79. }
  80.  
  81. // If we've waited over 1 second, then we timed out
  82. if(elapsed > timeOutMS) {
  83. // Invoke the user function with null input
  84. if(typeof(curAjax.container) == 'function'){
  85. curAjax.container(null);
  86. } else {
  87. // Alert the user
  88. alert("Command failed.\nConnection to development board was lost.");
  89. }
  90.  
  91. curAjax.ajaxReq.abort();
  92. curAjax.ajaxReq = null;
  93.  
  94. // If it's a repeatable request, then do so
  95. if(curAjax.repeat)
  96. newAJAXCommand(curAjax.url, curAjax.container, curAjax.repeat);
  97. continue;
  98. }
  99.  
  100. // Otherwise, just keep waiting
  101. ajaxList.push(curAjax);
  102. }
  103.  
  104. // Call ourselves again in 10ms
  105. setTimeout("pollAJAX()",curAjax.RepeatTime);
  106.  
  107. }// End pollAjax
  108.  
  109. /**
  110. * Parses the xmlResponse returned by an XMLHTTPRequest object
  111. *
  112. * @param the xmlData returned
  113. * @param the field to search for
  114. */
  115. function getXMLValue(xmlData, field) {
  116. try {
  117. if(xmlData.getElementsByTagName(field)[0].firstChild.nodeValue)
  118. return xmlData.getElementsByTagName(field)[0].firstChild.nodeValue;
  119. else
  120. return null;
  121. } catch(err) { return null; }
  122. }
  123.  
  124. //kick off the AJAX Updater
  125. setTimeout("pollAJAX()",500);
  126.  


oraz HTML:

  1. ~inc:header.inc~
  2. <div id="content">
  3.  
  4.  
  5.  
  6. <div id="status" >
  7. <div id="loading" style="display:none">Blad polaczenia</div>
  8. <div id="display">
  9. <table border=0 >
  10. <caption align="top">Karta </caption>
  11. <tr class="leds" >
  12.  
  13. <th><a id="led1" >&bull;</a></th>
  14. <th><a id="led2" >&bull;</a></th>
  15. <th><a id="led3" >&bull;</a></th>
  16. <th><a id="led4" >&bull;</a></th>
  17. <th><a id="led5" >&bull;</a></th>
  18. <th><a id="led6" >&bull;</a></th>
  19. <th><a id="led7" >&bull;</a></th>
  20. <th><a id="led8" >&bull;</a></th>
  21.  
  22. </tr>
  23.  
  24. <tr class="sm">
  25. <td><input type="button" class="sm" value=&nbsp;&nbsp;P1&nbsp;&nbsp onclick="newAJAXCommand('leds.cgi?led=1');"></td>
  26. <td><input type="button" class="sm" value=&nbsp;&nbsp;P2&nbsp;&nbsp onclick="newAJAXCommand('leds.cgi?led=2');"></td>
  27. <td><input type="button" class="sm" value=&nbsp;&nbsp;P3&nbsp;&nbsp onclick="newAJAXCommand('leds.cgi?led=3');"></td>
  28. <td><input type="button" class="sm" value=&nbsp;&nbsp;P4&nbsp;&nbsp onclick="newAJAXCommand('leds.cgi?led=4');"></td>
  29. <td><input type="button" class="sm" value=&nbsp;&nbsp;P5&nbsp;&nbsp onclick="newAJAXCommand('leds.cgi?led=5');"></td>
  30. <td><input type="button" class="sm" value=&nbsp;&nbsp;P6&nbsp;&nbsp onclick="newAJAXCommand('leds.cgi?led=6');"></td>
  31. <td><input type="button" class="sm" value=&nbsp;&nbsp;P7&nbsp;&nbsp onclick="newAJAXCommand('leds.cgi?led=7');"></td>
  32. <td><input type="button" class="sm" value=&nbsp;&nbsp;P8&nbsp;&nbsp onclick="newAJAXCommand('leds.cgi?led=8');"></td>
  33. </tr>
  34. <!-- </tbody> -->
  35.  
  36. </div>
  37.  
  38.  
  39.  
  40. </div>
  41.  
  42. <br><br><br><br><br><br><br><br><br><br>
  43.  
  44. <!--
  45. <h1>Welcome!</h1>
  46.  
  47. <table style="padding-left: 10px;">
  48. <tr><td><b>Stack Version:</b></td><td>&nbsp;</td><td>~version~</td></tr>
  49. <tr><td><b>Build Date:</b></td><td>&nbsp;</td><td>~builddate~</td></tr>
  50. </table>
  51. -->
  52. </div>
  53.  
  54.  
  55.  
  56.  
  57. <script type="text/javascript">
  58. <!--
  59. // Parses the xmlResponse from status.xml and updates the status box
  60. function updateStatus(xmlData) {
  61. // Check if a timeout occurred
  62. if(!xmlData)
  63. {
  64. document.getElementById('display').style.display = 'none';
  65. document.getElementById('loading').style.display = 'inline';
  66. return;
  67. }
  68.  
  69. // Make sure we're displaying the status display
  70. document.getElementById('loading').style.display = 'none';
  71. document.getElementById('display').style.display = 'inline';
  72.  
  73. // Loop over all the LEDs
  74. for(i = 1; i <9; i++) {
  75. if(getXMLValue(xmlData, 'led'+i) == '1')
  76. document.getElementById('led' + i).style.color = '#FF0000';
  77. else
  78. document.getElementById('led' + i).style.color = '#ddd';
  79. }
  80.  
  81.  
  82. }
  83. setTimeout("newAJAXCommand('status.xml', updateStatus, true,500)",100);
  84. //-->
  85.  
  86. <script type="text/javascript">
  87. <!--
  88. document.getElementById('hello').innerHTML = "~hellomsg~";
  89. //-->
  90.  
  91. ~inc:footer.inc~
  92.  


Muszę dopisać funkcję, która miałaby dzialac tak, że np przyciskiem nr2 wyłączam np. przycisk nr1 etc...
probowalem wpisac cos takiego:

  1.  
  2. <td><input type="button" class="sm" value=&nbsp;&nbsp;P1&nbsp;&nbsp onclick="newAJAXCommand('leds.cgi?led=1');newAJAXCommand('leds.cgi?led=8');"></td>
  3. <td><input type="button" class="sm" value=&nbsp;&nbsp;P2&nbsp;&nbsp onclick="newAJAXCommand('leds.cgi?led=2');newAJAXCommand('leds.cgi?led=1');"></td>
  4. <td><input type="button" class="sm" value=&nbsp;&nbsp;P3&nbsp;&nbsp onclick="newAJAXCommand('leds.cgi?led=3');newAJAXCommand('leds.cgi?led=2');"></td>
  5. <td><input type="button" class="sm" value=&nbsp;&nbsp;P4&nbsp;&nbsp onclick="newAJAXCommand('leds.cgi?led=4');ewAJAXCommand('leds.cgi?led=3');"></td>
  6. <td><input type="button" class="sm" value=&nbsp;&nbsp;P5&nbsp;&nbsp onclick="newAJAXCommand('leds.cgi?led=5');newAJAXCommand('leds.cgi?led=4');"></td>
  7. <td><input type="button" class="sm" value=&nbsp;&nbsp;P6&nbsp;&nbsp onclick="newAJAXCommand('leds.cgi?led=6');newAJAXCommand('leds.cgi?led=5');"></td>
  8. .....
  9. i tak do 8 przekaźnika

Wszystko dziala dopoki włączam je pokolei:) problem jest np. jak chce wlaczyc 3 i wylaczyc go np wlaczajac 7:)

Pozdrawiam
Adam