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:
var timeOutMS = 5000; //ms
/**
* Stores a queue of AJAX events to process
*/
var ajaxList = new Array();
/**
* Initiates a new AJAX command
*
* @param the url to access
* @param the document ID to fill, or a function to call with response XML (optional)
* @param true to repeat this call indefinitely (optional)
* @param a URL encoded string to be submitted as POST data (optional)
*/
function newAJAXCommand(url, container, repeat,time, data)
{
// Set up our object
var newAjax = new Object();
var theTimer = new Date();
newAjax.url = url;
newAjax.container = container;
newAjax.repeat = repeat;
newAjax.ajaxReq = null;
newAjax.RepeatTime=time;
// Create and send the request
if(window.XMLHttpRequest) {
newAjax.ajaxReq = new XMLHttpRequest();
newAjax.ajaxReq.open((data==null)?"GET":"POST", newAjax.url, true);
newAjax.ajaxReq.send(data);
// If we're using IE6 style (maybe 5.5 compatible too)
} else if(window.ActiveXObject) {
newAjax.ajaxReq = new ActiveXObject("Microsoft.XMLHTTP");
if(newAjax.ajaxReq) {
newAjax.ajaxReq.open((data==null)?"GET":"POST", newAjax.url, true);
newAjax.ajaxReq.send(data);
}
}
newAjax.lastCalled = theTimer.getTime();
// Store in our array
ajaxList.push(newAjax);
}
/**
* Loops over all pending AJAX events to determine
* if any action is required
*/
function pollAJAX() {
var curAjax = new Object();
var theTimer = new Date();
var elapsed;
// Read off the ajaxList objects one by one
for(i = ajaxList.length; i > 0; i--)
{
curAjax = ajaxList.shift();
if(!curAjax)
continue;
elapsed = theTimer.getTime() - curAjax.lastCalled;
// If we suceeded
if(curAjax.ajaxReq.readyState == 4 && curAjax.ajaxReq.status == 200) {
// If it has a container, write the result
if(typeof(curAjax.container) == 'function'){
curAjax.container(curAjax.ajaxReq.responseXML.documentElement);
} else if(typeof(curAjax.container) == 'string') {
document.getElementById(curAjax.container).innerHTML = curAjax.ajaxReq.responseText;
} // (otherwise do nothing for null values)
curAjax.ajaxReq.abort();
curAjax.ajaxReq = null;
// If it's a repeatable request, then do so
if(curAjax.repeat)
newAJAXCommand(curAjax.url, curAjax.container, curAjax.repeat,curAjax.RepeatTime);
continue;
}
// If we've waited over 1 second, then we timed out
if(elapsed > timeOutMS) {
// Invoke the user function with null input
if(typeof(curAjax.container) == 'function'){
curAjax.container(null);
} else {
// Alert the user
alert("Command failed.\nConnection to development board was lost.");
}
curAjax.ajaxReq.abort();
curAjax.ajaxReq = null;
// If it's a repeatable request, then do so
if(curAjax.repeat)
newAJAXCommand(curAjax.url, curAjax.container, curAjax.repeat);
continue;
}
// Otherwise, just keep waiting
ajaxList.push(curAjax);
}
// Call ourselves again in 10ms
setTimeout("pollAJAX()",curAjax.RepeatTime);
}// End pollAjax
/**
* Parses the xmlResponse returned by an XMLHTTPRequest object
*
* @param the xmlData returned
* @param the field to search for
*/
function getXMLValue(xmlData, field) {
try {
if(xmlData.getElementsByTagName(field)[0].firstChild.nodeValue)
return xmlData.getElementsByTagName(field)[0].firstChild.nodeValue;
else
return null;
} catch(err) { return null; }
}
//kick off the AJAX Updater
setTimeout("pollAJAX()",500);
oraz HTML:
~inc:header.inc~
<div id="loading" style="display:none">Blad polaczenia
</div>
<th><a id="led1" >•</a></th> <th><a id="led2" >•</a></th> <th><a id="led3" >•</a></th> <th><a id="led4" >•</a></th> <th><a id="led5" >•</a></th> <th><a id="led6" >•</a></th> <th><a id="led7" >•</a></th> <th><a id="led8" >•</a></th>
<td><input type="button" class="sm" value= P1   onclick="newAJAXCommand('leds.cgi?led=1');"></td> <td><input type="button" class="sm" value= P2   onclick="newAJAXCommand('leds.cgi?led=2');"></td> <td><input type="button" class="sm" value= P3   onclick="newAJAXCommand('leds.cgi?led=3');"></td> <td><input type="button" class="sm" value= P4   onclick="newAJAXCommand('leds.cgi?led=4');"></td> <td><input type="button" class="sm" value= P5   onclick="newAJAXCommand('leds.cgi?led=5');"></td> <td><input type="button" class="sm" value= P6   onclick="newAJAXCommand('leds.cgi?led=6');"></td> <td><input type="button" class="sm" value= P7   onclick="newAJAXCommand('leds.cgi?led=7');"></td> <td><input type="button" class="sm" value= P8   onclick="newAJAXCommand('leds.cgi?led=8');"></td> <!-- </tbody> -->
<!--
<h1>Welcome!</h1>
<table style="padding-left: 10px;">
<tr><td><b>Stack Version:</b></td><td> </td><td>~version~</td></tr>
<tr><td><b>Build Date:</b></td><td> </td><td>~builddate~</td></tr>
</table>
-->
<script type="text/javascript"> <!--
// Parses the xmlResponse from status.xml and updates the status box
function updateStatus(xmlData) {
// Check if a timeout occurred
if(!xmlData)
{
document.getElementById('display').style.display = 'none';
document.getElementById('loading').style.display = 'inline';
return;
}
// Make sure we're displaying the status display
document.getElementById('loading').style.display = 'none';
document.getElementById('display').style.display = 'inline';
// Loop over all the LEDs
for(i = 1; i <9; i++) {
if(getXMLValue(xmlData, 'led'+i) == '1')
document.getElementById('led' + i).style.color = '#FF0000';
else
document.getElementById('led' + i).style.color = '#ddd';
}
}
setTimeout("newAJAXCommand('status.xml', updateStatus, true,500)",100);
//-->
<script type="text/javascript"> <!--
document.getElementById('hello').innerHTML = "~hellomsg~";
//-->
~inc:footer.inc~
Muszę dopisać funkcję, która miałaby dzialac tak, że np przyciskiem nr2 wyłączam np. przycisk nr1 etc...
probowalem wpisac cos takiego:
<td><input type="button" class="sm" value= P1   onclick="newAJAXCommand('leds.cgi?led=1');newAJAXCommand('leds.cgi?led=8');"></td> <td><input type="button" class="sm" value= P2   onclick="newAJAXCommand('leds.cgi?led=2');newAJAXCommand('leds.cgi?led=1');"></td> <td><input type="button" class="sm" value= P3   onclick="newAJAXCommand('leds.cgi?led=3');newAJAXCommand('leds.cgi?led=2');"></td> <td><input type="button" class="sm" value= P4   onclick="newAJAXCommand('leds.cgi?led=4');ewAJAXCommand('leds.cgi?led=3');"></td> <td><input type="button" class="sm" value= P5   onclick="newAJAXCommand('leds.cgi?led=5');newAJAXCommand('leds.cgi?led=4');"></td> <td><input type="button" class="sm" value= P6   onclick="newAJAXCommand('leds.cgi?led=6');newAJAXCommand('leds.cgi?led=5');"></td> .....
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
Ten post edytował beeeeer 1.12.2012, 16:02:09