Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Problem with XMLHTTPRequest [modified]

Problem with XMLHTTPRequest [modified]

Scheduled Pinned Locked Moved Web Development
announcementc++comsysadminxml
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xfitr2
    wrote on last edited by
    #1

    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>

    A X 2 Replies Last reply
    0
    • X xfitr2

      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>

      A Offline
      A Offline
      andyharman
      wrote on last edited by
      #2

      You have specified that the request will be asynchronous: req.open("GET", url, **true**); Try changing the above "true" to "false".

      X 2 Replies Last reply
      0
      • A andyharman

        You have specified that the request will be asynchronous: req.open("GET", url, **true**); Try changing the above "true" to "false".

        X Offline
        X Offline
        xfitr2
        wrote on last edited by
        #3

        Thank you for your response. I just tried your suggestion and now it will process the first request in the for loop and then stops.

        1 Reply Last reply
        0
        • A andyharman

          You have specified that the request will be asynchronous: req.open("GET", url, **true**); Try changing the above "true" to "false".

          X Offline
          X Offline
          xfitr2
          wrote on last edited by
          #4

          I think that I will just build an xmldoc and send that to the asp page. This way, there will only be one XmlHTTPRequest sent per user click even if there are multiple items selected.

          1 Reply Last reply
          0
          • X xfitr2

            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>

            X Offline
            X Offline
            xfitr2
            wrote on last edited by
            #5

            To answer my own problem. It seems that I will have to create 'virtual threads' in javascript to handle the callback event. http://www.developer.com/lang/jscript/article.php/10939_3592016_2[^]

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups