Loading ...
Sorry, an error occurred while loading the content.

Infinite loop from YAHOO.util.Connect.asyncRequest

Expand Messages
  • dugscoular
    Hi All, I have a weird problem with YAHOO.util.Connect.asyncRequest going into an infinite loop when I attempt to modify a DOM element from within the success
    Message 1 of 3 , Feb 15, 2006
    • 0 Attachment
      Hi All,

      I have a weird problem with YAHOO.util.Connect.asyncRequest
      going into an infinite loop when I attempt to modify a DOM element
      from within the success callback.

      I have the following callback structure defined:

      var netInfoCallback = {
      success:netInfoSuccess,
      failure:netInfoFailure
      };

      The callback is installed via:

      YAHOO.util.Connect.asyncRequest('GET', button.form.action +
      '?callback=getNetInfo&ip=' +
      host, netInfoCallback, null);

      The failure routine works perfectly. However the success routine
      gets called over and over again returning a status of 200 each
      time and I have to kill the browser:

      var netInfoSuccess = function(o) {
      spinner = getElement('lookupIcon');
      // Stop our spinner.
      spinner.src = 'images/doug/view-refresh.png';
      getElement('lookupvalue').style.cursor = 'default';

      if (o.responseText.match(/^error: /i)) {
      // The server reported an error... tell the punter!
      alert("Failed to lookup host, please correct the hostname and retry.
      Detailed error: [" + o.responseText + "]");
      }
      else {
      // Okay we got a good response from the server.
      alert(o.status);
      lines = o.responseText.split("\n");
      myElement = getElement('netmaskvalue');
      myElement.setAttribute('value', lines[0]);
      myElement = getElement('gwvalue');
      myElement.setAttribute('value', lines[1]);

      var nisDomain = lines[2];
      var myNISDomain = getElement('hiddenNISDomain');
      myNISDomain.setAttribute('value', nisDomain);
      }
      };

      If I comment out the last line of the else above:

      // myNISDomain.setAttribute('value', nisDomain);

      Everything works as expected. The if () part has always worked
      since it makes no change to the DOM. The myNISDomain is simply
      a hidden form element with no javascript handlers attached.

      GetElement is just a browser agnostic helper:

      // Browser insensitive getElement by ID.
      function getElement(aID) {
      var rv = (document.getElementById) ?
      document.getElementById(aID) :
      document.all[aID];
      return rv;
      }

      Has anyone an idea why the success method would be looping ?

      Maybe I'm not using it right... the API docs could do with far more
      examples IMHO.

      Anyway, if anyone has an idea I'd dearly love to here it.

      P.S. This is on Mozilla 1.7.12 and Firefox 1.0.7. IE 6.0.2800.1106
      doesn't have this problem.

      Cheers,

      Doug
    • dugscoular
      Hi All, My apologies... it turned out that my hidden nisDomain form element hadn t actually been written out to the form... so I guess the behaviour was
      Message 2 of 3 , Feb 15, 2006
      • 0 Attachment
        Hi All,

        My apologies... it turned out that my hidden "nisDomain" form
        element hadn't actually been written out to the form... so
        I guess the behaviour was reasonable... the success routine
        aborted when trying to set a null element and so was called
        again and again...

        Sorry for impuning the connection utility... [Doug falls on sword]

        P.S. Can we get release numbers on the yui.zip files so we know
        when to upgrade to new releases ?

        Cheers,

        Doug
      • Thomas S. Sha
        ... There is a fix in the queue for the next release. In FF/Moz, exceptions halt at handleTransactionResponse and never clears the polling interval. Clearing
        Message 3 of 3 , Feb 16, 2006
        • 0 Attachment
          --- In ydn-javascript@yahoogroups.com, "dugscoular" <dscoular@...> wrote:
          >
          > Hi All,
          >
          > My apologies... it turned out that my hidden "nisDomain" form
          > element hadn't actually been written out to the form... so
          > I guess the behaviour was reasonable... the success routine
          > aborted when trying to set a null element and so was called
          > again and again...
          >
          > Sorry for impuning the connection utility... [Doug falls on sword]
          >
          > P.S. Can we get release numbers on the yui.zip files so we know
          > when to upgrade to new releases ?
          >
          > Cheers,
          >
          > Doug

          There is a fix in the queue for the next release. In FF/Moz,
          exceptions halt at handleTransactionResponse and never clears the
          polling interval. Clearing the poll first, and then handling the
          results resolves this nastiness.

          *** Original ***
          Lines 205 - 206:
          oConn.handleTransactionResponse(o, callback);
          window.clearInterval(poll);

          *** Corrected ***
          window.clearInterval(poll);
          oConn.handleTransactionResponse(o, callback);

          Regards,
          Thomas
        Your message has been successfully submitted and would be delivered to recipients shortly.