calling GetResponse multiple times not working?
so i amended Mike G.'s restful led demo html code to show/control pins 23-27.
all works as expected except for one thing.
i added multiple calls to GetResponse for each led, thinking it would turn on all of the led's it does not. it only turns on led23. if i comment out the first GetResponse it turns on led24, and so on.
it seemed like it was doing the first GetResponse then bailing on the script, but then i added an alert box for each step, and i get all 5 alert windows, so i am now lost!
does anyone see a problem with what im trying?
thanks!
all works as expected except for one thing.
i added multiple calls to GetResponse for each led, thinking it would turn on all of the led's it does not. it only turns on led23. if i comment out the first GetResponse it turns on led24, and so on.
it seemed like it was doing the first GetResponse then bailing on the script, but then i added an alert box for each step, and i get all 5 alert windows, so i am now lost!
does anyone see a problem with what im trying?
thanks!
<body>
<div id="content">
<h1><span id="time">Testing...</span></h1>
<h2>PIN 23: <span id="pin23">State</span></h2>
<p>
<a href="#" onClick="return getRequest('led/23/on', 'pin23');">LED On</a> ::
<a href="#" onClick="return getRequest('led/23/off', 'pin23');">LED Off</a>
</p>
<h2>PIN 24: <span id="pin24">State</span></h2>
<p>
<a href="#" onClick="return getRequest('led/24/on', 'pin24');">LED On</a> ::
<a href="#" onClick="return getRequest('led/24/off', 'pin24');">LED Off</a>
</p>
<h2>PIN 25: <span id="pin25">State</span></h2>
<p>
<a href="#" onClick="return getRequest('led/25/on', 'pin25');">LED On</a> ::
<a href="#" onClick="return getRequest('led/25/off', 'pin25');">LED Off</a>
</p>
<h2>PIN 26: <span id="pin26">State</span></h2>
<p>
<a href="#" onClick="return getRequest('led/26/on', 'pin26');">LED On</a> ::
<a href="#" onClick="return getRequest('led/26/off', 'pin26');">LED Off</a>
</p>
<h2>PIN 27: <span id="pin27">State</span></h2>
<p>
<a href="#" onClick="return getRequest('led/27/on', 'pin27');">LED On</a> ::
<a href="#" onClick="return getRequest('led/27/off', 'pin27');">LED Off</a>
</p>
</div>
<script language="javascript" type="text/javascript">
alert("check pin23 now");
getRequest('led/23/on', 'pin23');
alert("check pin24 now");
getRequest('led/24/on', 'pin24');
alert("check pin25 now");
getRequest('led/25/on', 'pin25');
alert("check pin26 now");
getRequest('led/26/on', 'pin26');
alert("check pin27 now");
getRequest('led/27/on', 'pin27');
</script>
</body>

Comments
//XmlHttpRequest object var req = getXmlHttpRequestObject(); var htmlTarget; function getRequest(resource, elementId) { // handle the case where a querystring is not detected var char = "&"; if(resource.indexOf("?", 0) == -1) { char = "?"; } if (req.readyState == 4 || req.readyState == 0) { req.open("GET", resource + char + 'ms=' + new Date().getTime(), true); req.onreadystatechange = handleResponse; htmlTarget = elementId; req.send(null); return false; } } function handleResponse() { if (req.readyState == 4) { parseState(req.responseXML); } } function parseState(xDoc) { var target = document.getElementById(htmlTarget); target.innerHTML = xDoc.getElementsByTagName("led")[0].childNodes[0].nodeValue; } function parseTime(xDoc) { var target = document.getElementById(htmlTarget); target.innerHTML = xDoc.getElementsByTagName("time")[0].childNodes[0].nodeValue; }i been keeping pase with the repository, and have the latest stringmethods already.
Better yet, why not send one command like led/all/on and handle the logic in server side SPIN?
PRI RestLed(id) | pin, state, temp, headerLen '' URL => led\pin\on|off|check ' Get the pin and state pin := Request.GetPathNode(id, 1) state := Request.GetPathNode(id, 2) ' Convert the ASCII pin number to an integer bytemove(@numBuff, pin, strsize(pin)) temp := str.ToInteger(@numBuff) if(temp < 23 OR temp > 27) temp := 23 if (strcomp(string("check"), state )) temp := ina[temp] if temp == 1 state := string("on") else state := string("off") elseif (strcomp(string("on"), state )) PinState(temp, 1) else PinState(temp, 0) bytefill(@numBuff, 0, strsize(pin)) dynamicContentPtr := @tempBuff PushDynamicContent(@xmlencode) PushDynamicContent(string("<root application='multisocket'><led id='")) PushDynamicContent(pin) PushDynamicContent(string("'><![CDATA[")) PushDynamicContent(state) PushDynamicContent(string("]]></led></root>")) ' Build and send the header ' Send the value of led= on or off headerLen := Response.BuildHeader(string("xml"), 200, false) Socket.txTCP(id, @txdata, headerLen) StringSend(id, @tempBuff) bytefill(@tempBuff, 0, TEMP_BUFFER) return