Menu

onChange and onComplete

Help
Nucleo
2006-07-07
2013-04-02
  • Nucleo

    Nucleo - 2006-07-07

    Hi Carlos,

    I'm trying to use the onChange or onComplete to trigger something after I succesfully received/posted the data. I'm currently using an easy form that wait 5 second (in PHP) and then display some text. What I want to be able to do is to be able to trigger a ajax_get() after I have used a ajax_postbyid(). Right now the onComplete or onChange is trigged before I get any data back from my request. Any clue on how I could do this?

    I have updated my version of Clean to 3.1

    Thanks

     
    • Carlos Eduardo Goncalves

      Hi Nucleo,

      If you are using the built in onChange handler your message's onComplete will be called at the request response (readyState == 4).
      To perform the ajax_get after the ajax_post, you only have to apply a onComplete handler to message used at the the ajax_post.
      The sequence of your requests should be:

      1 - ajax_post(msg_1)
      2 - msg_1.onChange() -> calls msg_1.onComplete if assigned
      3 - msg_1.onComplete -> **** you must call ajax_get(msg_2) here *****
      4-  msg_2.onChange() -> calls onComplete (if assigned)
      5 -  msg_2.onComplete()

      Regards.

       
      • Nucleo

        Nucleo - 2006-07-09

        I tried to set the onComplete() of the post to an alert but the alert arrive before the loading logo disapear.

        Any clues?

         
    • Carlos Eduardo Goncalves

      It does not mean that onComplete is called before onChange (it is not possible using the built in onChange handler).
      There is a delay applied to progress synchronization, that's all.

       
    • Blaine Ehrhart

      Blaine Ehrhart - 2006-09-08

      function postit (url,value,method,id) {
          message = Clean.createSimpleMessage(url, null, null);
          message.method=method;
          message.value=value;
          message.id=id;
          message.silent = true;
          message.onComplete = pooling;
         
      }

      function pooling(status){
          Clean.doGet(message);
      }

      Could this work?

       
    • Carlos Eduardo Goncalves

      // Declare the global var message
      var message;

      function postit (url,value,method,id) {
      // That is ok
      message = Clean.createSimpleMessage(url, null, null);

      // These lines are not required
      message.method=method;
      message.value=value;
      message.id=id; /*the id is define by the engine not by you */

      // Thats is ok
      message.silent = true;
      message.onComplete = pooling;

      /* Here you post it. It performs some sets for you internally (message.method=POST, message.value=value). It also returns a valid message id that you can store.
      */
      message.id = Clean.doPost(message, value, false);
      }

      /* This function will work fine only if there is only one message at message queue in each request/response. If there are other messages been sent the message.id will point to other message in futher interactions. To avoid it create a function similar to the postit that perform a HTTP GET request using the method Clean.doGet(message)*/
      function pooling(status){
      Clean.doGet(message);
      }

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.