Problem with XMLHTTPRequest [modified]
-
I am having a problem where I am sending XMLHTTPRequest in a for loop [function: updateStatus()] and only the last row in the loop's style attributes get updated on the page [function: StatusChange()], but each XMLHTTPRequest is making the correct change on the server. Is there a way to wait for each callback, change the style attributes and then go on to the next call? Any suggestions would be helpful. Summary: UpdateStatus() |_calls StatusChange() |_loadXMLDoc() processReqChange() |_call StatusChange() -> with a response to update nodes
var req; function loadXMLDoc(url) { req = false; // branch for native XMLHttpRequest object if(window.XMLHttpRequest && !(window.ActiveXObject)) { try { req = new XMLHttpRequest(); } catch(e) { req = false; } // branch for IE/Windows ActiveX version } else if(window.ActiveXObject) { try { req = new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) { try { req = new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) { req = false; } } } if(req) { req.open("GET", url, true); req.onreadystatechange = processReqChange; req.send(""); } } function processReqChange() { //only if req shows "complete" if (req.readyState == 4) { //only if "OK" if (req.status == 200) { //...processing statements go here response = req.responseXML.documentElement; method = response.getElementsByTagName('method')[0].firstChild.data; result = response.getElementsByTagName('result')[0].firstChild.data; status = response.getElementsByTagName('status')[0].firstChild.data; invoice = response.getElementsByTagName('invoice')[0].firstChild.data; eval(method + '(invoice, status, result)'); } else { alert('There was a problem retrieving the XML data:\n ' + req.statusText); } } } function updateStatus(status) { var tblrows = document.getElementById('wtgridScreen_dgScreen').rows; if (tblrows != null) { for (i = 1; i < tblrows.length - 1; i++) { if(tblrows[i].cells[0].children[0].children[0].checked) { var sid = tblrows[i].cells[1].attributes['record_keys'].value; StatusChange(sid, status, ''); //Input Mode } } } } function StatusChange(id, status, response) { if (response != '') { //Response Mode if (response == 'Success') { tblrows = document.getElementB</x-turndown>
-
I am having a problem where I am sending XMLHTTPRequest in a for loop [function: updateStatus()] and only the last row in the loop's style attributes get updated on the page [function: StatusChange()], but each XMLHTTPRequest is making the correct change on the server. Is there a way to wait for each callback, change the style attributes and then go on to the next call? Any suggestions would be helpful. Summary: UpdateStatus() |_calls StatusChange() |_loadXMLDoc() processReqChange() |_call StatusChange() -> with a response to update nodes
var req; function loadXMLDoc(url) { req = false; // branch for native XMLHttpRequest object if(window.XMLHttpRequest && !(window.ActiveXObject)) { try { req = new XMLHttpRequest(); } catch(e) { req = false; } // branch for IE/Windows ActiveX version } else if(window.ActiveXObject) { try { req = new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) { try { req = new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) { req = false; } } } if(req) { req.open("GET", url, true); req.onreadystatechange = processReqChange; req.send(""); } } function processReqChange() { //only if req shows "complete" if (req.readyState == 4) { //only if "OK" if (req.status == 200) { //...processing statements go here response = req.responseXML.documentElement; method = response.getElementsByTagName('method')[0].firstChild.data; result = response.getElementsByTagName('result')[0].firstChild.data; status = response.getElementsByTagName('status')[0].firstChild.data; invoice = response.getElementsByTagName('invoice')[0].firstChild.data; eval(method + '(invoice, status, result)'); } else { alert('There was a problem retrieving the XML data:\n ' + req.statusText); } } } function updateStatus(status) { var tblrows = document.getElementById('wtgridScreen_dgScreen').rows; if (tblrows != null) { for (i = 1; i < tblrows.length - 1; i++) { if(tblrows[i].cells[0].children[0].children[0].checked) { var sid = tblrows[i].cells[1].attributes['record_keys'].value; StatusChange(sid, status, ''); //Input Mode } } } } function StatusChange(id, status, response) { if (response != '') { //Response Mode if (response == 'Success') { tblrows = document.getElementB</x-turndown>
You have specified that the request will be asynchronous:
req.open("GET", url, **true**);
Try changing the above "true" to "false". -
You have specified that the request will be asynchronous:
req.open("GET", url, **true**);
Try changing the above "true" to "false". -
You have specified that the request will be asynchronous:
req.open("GET", url, **true**);
Try changing the above "true" to "false". -
I am having a problem where I am sending XMLHTTPRequest in a for loop [function: updateStatus()] and only the last row in the loop's style attributes get updated on the page [function: StatusChange()], but each XMLHTTPRequest is making the correct change on the server. Is there a way to wait for each callback, change the style attributes and then go on to the next call? Any suggestions would be helpful. Summary: UpdateStatus() |_calls StatusChange() |_loadXMLDoc() processReqChange() |_call StatusChange() -> with a response to update nodes
var req; function loadXMLDoc(url) { req = false; // branch for native XMLHttpRequest object if(window.XMLHttpRequest && !(window.ActiveXObject)) { try { req = new XMLHttpRequest(); } catch(e) { req = false; } // branch for IE/Windows ActiveX version } else if(window.ActiveXObject) { try { req = new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) { try { req = new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) { req = false; } } } if(req) { req.open("GET", url, true); req.onreadystatechange = processReqChange; req.send(""); } } function processReqChange() { //only if req shows "complete" if (req.readyState == 4) { //only if "OK" if (req.status == 200) { //...processing statements go here response = req.responseXML.documentElement; method = response.getElementsByTagName('method')[0].firstChild.data; result = response.getElementsByTagName('result')[0].firstChild.data; status = response.getElementsByTagName('status')[0].firstChild.data; invoice = response.getElementsByTagName('invoice')[0].firstChild.data; eval(method + '(invoice, status, result)'); } else { alert('There was a problem retrieving the XML data:\n ' + req.statusText); } } } function updateStatus(status) { var tblrows = document.getElementById('wtgridScreen_dgScreen').rows; if (tblrows != null) { for (i = 1; i < tblrows.length - 1; i++) { if(tblrows[i].cells[0].children[0].children[0].checked) { var sid = tblrows[i].cells[1].attributes['record_keys'].value; StatusChange(sid, status, ''); //Input Mode } } } } function StatusChange(id, status, response) { if (response != '') { //Response Mode if (response == 'Success') { tblrows = document.getElementB</x-turndown>