Ajax is not asynchronous

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rex the Strange

    Ajax is not asynchronous

    Seriously.

    I have a flash animation that I was trying to run during ajax calls -
    sort of eyecandy - but it would freeze whenever the ajax call was
    being made. Then I found out it wasn't just the flash, it was the
    entire page - could scroll, type, do jack.

    Asynchronous javascript? Yeah, right. (and before you suggest it, that
    isAscync parameter in the open function doesn't seem to do jack unless
    I'm not using a boolean correctly)

    </sarcasm>
  • Joost Diepenmaat

    #2
    Re: Ajax is not asynchronous

    Rex the Strange <roger.main@wid getinc.comwrite s:
    Asynchronous javascript? Yeah, right. (and before you suggest it, that
    isAscync parameter in the open function doesn't seem to do jack unless
    I'm not using a boolean correctly)
    >
    </sarcasm>
    Nice sarcasm. Show the code.

    --
    Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/

    Comment

    • Rex the Strange

      #3
      Re: Ajax is not asynchronous

      On Apr 6, 10:54 am, Rex the Strange <roger.m...@wid getinc.comwrote :
      On Apr 5, 6:06 pm, Joost Diepenmaat <jo...@zeekat.n lwrote:
      >
      Rex the Strange <roger.m...@wid getinc.comwrite s:
      >
      Asynchronous javascript? Yeah, right. (and before you suggest it, that
      isAscync parameter in the open function doesn't seem to do jack unless
      I'm not using a boolean correctly)
      >
      </sarcasm>
      >
      Nice sarcasm. Show the code.
      >
      --
      Joost Diepenmaat | blog:http://joost.zeekat.nl/|work:http://zeekat.nl/
      >
      Gladly:
      >
      /**********/
      >
      function ajax_object (callback_field ) {
              var request_object;
              var callback = document.getEle mentById (callback_field );
              var eyecandy = document.getEle mentById ("flash_cell ");
              var parameters = new ajax_parameters ;
      >
              request_object = ajax_object ();
      >
              /********/
      >
              function show_eyecandy () {
                      callback.innerH TML = blank;
                      eyecandy.style ["visibility "] = "visible";
              }// show_eyecandy;
      >
              /********/
      >
              function hide_eyecandy () {
                      callback.style ["visibility "] = "visible";
                      eyecandy.style ["visibility "] = "hidden";
              }// hide_eyecandy;
      >
              /********/
      >
              function ajax_object () {
                      var object;
                      try {
                              object = new XMLHttpRequest ();
                      } catch (except) {
                              try {
                                      object =new ActiveXObject ("Msxml2.XMLHTT P");
                              } catch (except) {
                                      try {
                                              object = new ActiveXObject ("Microsoft.XML HTTP");
                                      } catch (except) {
                                              return false;
                                      }// try
                              }// try
                      }// try
                      return object;
              }// ajax_object;
      >
              /********/
      >
              this.add_parame ters = function (name, value) {
                      parameters.add (name, value);
              }// add_parameters;
      >
              /********/
      >
              this.callback_f unction = function (data) {
                      if (request_object .readyState != 4) return;
                      callback.innerH TML = request_object. responseText;
                      hide_eyecandy ();
              }// callback_functi on;
      >
              /********/
      >
              this.send = function (destination) {
                      show_eyecandy ();
                      request_object. onreadystatecha nge = this..callback_ function;
                      request_object. open ("post", destination, true);
                      request_object. setRequestHeade r ("Content-Type", "applicatio n/x-www-
      form-urlencoded; charset=UTF-8");
                      request_object. send (parameters.ren der ());
              }// this.send;
      >
              /********/
      >
      }// ajax_object;
      >
      /**********/
      >
      function ajax_parameters () {
              var items = [];
      >
              this.add = function (name, value) {
                      items.push (name + "=" + value);
              }// add;
      >
              this.render = function () {
                      return items.join ("&");
              }// render;
      >
      }// ajax_parameters ;
      >
      /**********/
      Well, I've shown the code. What am I doing wrong?

      Comment

      • VK

        #4
        Re: Ajax is not asynchronous

        On Apr 30, 12:45 am, Rex the Strange <roger.m...@wid getinc.comwrote :
        On Apr 6, 10:54 am, Rex the Strange <roger.m...@wid getinc.comwrote :
        >
        >
        >
        On Apr 5, 6:06 pm, Joost Diepenmaat <jo...@zeekat.n lwrote:
        >
        Rex the Strange <roger.m...@wid getinc.comwrite s:
        >
        Asynchronous javascript? Yeah, right. (and before you suggest it, that
        isAscync parameter in the open function doesn't seem to do jack unless
        I'm not using a boolean correctly)
        >
        </sarcasm>
        >
        Nice sarcasm. Show the code.
        >
        --
        Joost Diepenmaat | blog:http://joost.zeekat.nl/|work:http://zeekat.nl/
        >
        Gladly:
        >
        /**********/
        >
        function ajax_object (callback_field ) {
        var request_object;
        var callback = document.getEle mentById (callback_field );
        var eyecandy = document.getEle mentById ("flash_cell ");
        var parameters = new ajax_parameters ;
        >
        request_object = ajax_object ();
        >
        /********/
        >
        function show_eyecandy () {
        callback.innerH TML = blank;
        eyecandy.style ["visibility "] = "visible";
        }// show_eyecandy;
        >
        /********/
        >
        function hide_eyecandy () {
        callback.style ["visibility "] = "visible";
        eyecandy.style ["visibility "] = "hidden";
        }// hide_eyecandy;
        >
        /********/
        >
        function ajax_object () {
        var object;
        try {
        object = new XMLHttpRequest ();
        } catch (except) {
        try {
        object = new ActiveXObject ("Msxml2.XMLHTT P");
        } catch (except) {
        try {
        object = new ActiveXObject ("Microsoft.XML HTTP");
        } catch (except) {
        return false;
        }// try
        }// try
        }// try
        return object;
        }// ajax_object;
        >
        /********/
        >
        this.add_parame ters = function (name, value) {
        parameters.add (name, value);
        }// add_parameters;
        >
        /********/
        >
        this.callback_f unction = function (data) {
        if (request_object .readyState != 4) return;
        callback.innerH TML = request_object. responseText;
        hide_eyecandy ();
        }// callback_functi on;
        >
        /********/
        >
        this.send = function (destination) {
        show_eyecandy ();
        request_object. onreadystatecha nge = this.callback_f unction;
        request_object. open ("post", destination, true);
        request_object. setRequestHeade r ("Content-Type", "applicatio n/x-www-
        form-urlencoded; charset=UTF-8");
        request_object. send (parameters.ren der ());
        }// this.send;
        >
        /********/
        >
        }// ajax_object;
        >
        /**********/
        >
        function ajax_parameters () {
        var items = [];
        >
        this.add = function (name, value) {
        items.push (name + "=" + value);
        }// add;
        >
        this.render = function () {
        return items.join ("&");
        }// render;
        >
        }// ajax_parameters ;
        >
        /**********/
        >
        Well, I've shown the code. What am I doing wrong?
        That was answered N times in this group: the graphics context is not
        being updated until exit from the current execution context. With your
        nested functions - besides being memory leaking like an old bucket -
        you never give this opportunity to the engine. use setTimeout at
        least.

        Comment

        • Joost Diepenmaat

          #5
          Re: Ajax is not asynchronous

          Rex the Strange <roger.main@wid getinc.comwrite s:
          >Gladly:
          Ok ok, I didn't reply to your code the first time, because I couldn't
          find the error. Though the naming of some of the variables did make my
          head hurt. Here's what I've got.
          >/**********/
          >>
          >function ajax_object (callback_field ) {
          >        var request_object;
          >        var callback = document.getEle mentById (callback_field );
          callbacks are usually functions.
          >        var eyecandy = document.getEle mentById ("flash_cell ");
          >        var parameters = new ajax_parameters ;
          >>
          >        request_object = ajax_object ();
          >>
          I note that you're calling a nested ajax_object() function within this
          ajax_object() function. Also the outer function *seems* to be a
          constructor, while the inner function isn't. Can't see how you're
          calling the outer function, though.
          >        /********/
          Does this mean you've left some code out here?
          >        function show_eyecandy () {
          >                callback.innerH TML = blank;
          >                eyecandy.style ["visibility "] = "visible";
          this is probably better (or at least, shorter) written as

          eyecandy.style. visibilitiy = "visible";
          >        }// show_eyecandy;
          >>
          >>
          >        /********/
          >>
          >        function hide_eyecandy () {
          >                callback.style ["visibility "] = "visible";
          >                eyecandy.style ["visibility "] = "hidden";
          same here.
          >        }// hide_eyecandy;
          >>
          >        /********/
          >>
          >        function ajax_object () {
          >                var object;
          >                try {
          >                        object = new XMLHttpRequest ();
          >                } catch (except) {
          >                        try {
          >                                object = new ActiveXObject ("Msxml2.XMLHTT P");
          >                        } catch (except) {
          >                                try {
          >                                        object = new ActiveXObject ("Microsoft.XML HTTP");
          >                                } catch (except) {
          >                                        return false;
          >                                }// try
          >                        }// try
          >                }// try
          >                return object;
          >        }// ajax_object;
          >>
          >        /********/
          >>
          >        this.add_parame ters = function (name, value) {
          >                parameters.add (name, value);
          >        }// add_parameters;
          >>
          >        /********/
          >>
          >        this.callback_f unction = function (data) {
          >                if (request_object .readyState != 4) return;
          >                callback.innerH TML = request_object. responseText;
          >                hide_eyecandy ();
          >        }// callback_functi on;
          >>
          >        /********/
          >>
          >        this.send = function (destination) {
          >                show_eyecandy ();
          >                request_object. onreadystatecha nge = this.callback_f unction;
          >                request_object. open ("post", destination, true);
          >                request_object. setRequestHeade r ("Content-Type", "applicatio n/x-www-
          >form-urlencoded; charset=UTF-8");
          >                request_object. send (parameters.ren der ());
          >        }// this.send;
          >>
          >        /********/
          >>
          >}// ajax_object;
          >>
          >/**********/
          >>
          >function ajax_parameters () {
          >        var items = [];
          >>
          >        this.add = function (name, value) {
          >                items.push (name + "=" + value);
          >        }// add;
          >>
          >        this.render = function () {
          >                return items.join ("&");
          >        }// render;
          this will break if your names or values contain any characters that need to
          be urlencoded.
          >}// ajax_parameters ;
          >>
          >/**********/
          >
          Well, I've shown the code. What am I doing wrong?
          Dunno. Got a URL?

          Joost.

          --
          Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/

          Comment

          Working...