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

Re: [ydn-javascript] How to send argument to Connection Manager's startRequest function

Expand Messages
  • Eric Miraglia
    andre22miami, There are a few problems in the code you posted: 1. myarg is not defined at the point where you re passing it in to your startRequest function.
    Message 1 of 4 , Jan 31, 2007
    • 0 Attachment
      andre22miami,

      There are a few problems in the code you posted:

      1.  myarg is not defined at the point where you're passing it in to your startRequest function.
      2.  Your argument needs to go in the callback object's argument member.
      3.  In your handleSuccess method, you'll need to look at o.argument for your argument data; remember, o in that case is your response object.

      So, your code might look something like this:

      var AjaxObject = { 
      handleSuccess:function(o){ 
      console.log('succeeded'); 
      // the 'myarg' argument is available here
      console.log(o.argument.arg1);
      }, 

      handleFailure:function(o){ alert('failed'); }, 

      startRequest:function() { 
      console.log("here");
      var request =
      YAHOO.util.Connect.asyncRequest('GET','get.html', callback); 
      } 
      }; 

      var callback = { 
      success:AjaxObject.handleSuccess, 
      failure:AjaxObject.handleFailure,
      // send a 'myarg' argument to the start function
      argument: {arg1: "value1"}
      }; 


      AjaxObject.startRequest();

      This appears to work well for me.

      Regards,
      Eric
      ______________________________________________
      Eric Miraglia
      Yahoo! User Interface Library


      On Jan 31, 2007, at 3:23 AM, andre22miami wrote:

      Can't seem to figure this out. When I initiate the Ajax startRequest
      call I want to send an argument to it and have it reach the
      handleSuccess function. How do I accomplish the following:

      var AjaxObject = {
      handleSuccess:function(o){
      alert('succeeded');
      // the 'myarg' argument is available here
      },

      handleFailure:function(o){ alert('failed'); },

      startRequest:function() {
      var request =
      YAHOO.util.Connect.asyncRequest('GET','http://my_url_here', callback);
      }
      };

      var callback = {
      success:AjaxObject.handleSuccess,
      failure:AjaxObject.handleFailure
      };

      // send a 'myarg' argument to the start function
      AjaxObject.startRequest(myarg);


    • andre22miami
      Hi, Thanks for the reply. I am familiar with the argument: option but it doesn t offer what I m looking for. It requires that I hard code the argument in the
      Message 2 of 4 , Mar 20, 2007
      • 0 Attachment
        Hi,

        Thanks for the reply. I am familiar with the "argument:" option but it
        doesn't offer what I'm looking for. It requires that I hard code the
        argument in the callback declaration. I want to be able to send a
        dynamic argument during the startRequest call:

        AjaxObject.startRequest(myarg)

        ...and have myarg available in the success handler. I still haven't
        figured out how to do this.

        --- In ydn-javascript@yahoogroups.com, Eric Miraglia <miraglia@...> wrote:
        >
        > andre22miami,
        >
        > There are a few problems in the code you posted:
        >
        > 1. myarg is not defined at the point where you're passing it in to
        > your startRequest function.
        > 2. Your argument needs to go in the callback object's argument member.
        > 3. In your handleSuccess method, you'll need to look at o.argument
        > for your argument data; remember, o in that case is your response
        > object.
        >
        > So, your code might look something like this:
        >
        > var AjaxObject = {
        > handleSuccess:function(o){
        > console.log('succeeded');
        > // the 'myarg' argument is available here
        > console.log(o.argument.arg1);
        > },
        >
        > handleFailure:function(o){ alert('failed'); },
        >
        > startRequest:function() {
        > console.log("here");
        > var request =
        > YAHOO.util.Connect.asyncRequest('GET','get.html', callback);
        > }
        > };
        >
        > var callback = {
        > success:AjaxObject.handleSuccess,
        > failure:AjaxObject.handleFailure,
        > // send a 'myarg' argument to the start function
        > argument: {arg1: "value1"}
        > };
        >
        >
        > AjaxObject.startRequest();
        >
        > This appears to work well for me.
        >
        > Regards,
        > Eric
        > ______________________________________________
        > Eric Miraglia
        > Yahoo! User Interface Library
        >
        >
        > On Jan 31, 2007, at 3:23 AM, andre22miami wrote:
        >
        > > Can't seem to figure this out. When I initiate the Ajax startRequest
        > > call I want to send an argument to it and have it reach the
        > > handleSuccess function. How do I accomplish the following:
        > >
        > > var AjaxObject = {
        > > handleSuccess:function(o){
        > > alert('succeeded');
        > > // the 'myarg' argument is available here
        > > },
        > >
        > > handleFailure:function(o){ alert('failed'); },
        > >
        > > startRequest:function() {
        > > var request =
        > > YAHOO.util.Connect.asyncRequest('GET','http://my_url_here', callback);
        > > }
        > > };
        > >
        > > var callback = {
        > > success:AjaxObject.handleSuccess,
        > > failure:AjaxObject.handleFailure
        > > };
        > >
        > > // send a 'myarg' argument to the start function
        > > AjaxObject.startRequest(myarg);
        > >
        > >
        > >
        >
      • tssha
        ... Define the property *argument* within startRequest. For example: var AjaxObject = { handleSuccess:function(o){ // the alert will show 123
        Message 3 of 4 , Mar 21, 2007
        • 0 Attachment
          --- In ydn-javascript@yahoogroups.com, "andre22miami"
          <andre22wire@...> wrote:
          >
          > Hi,
          >
          > Thanks for the reply. I am familiar with the "argument:" option but it
          > doesn't offer what I'm looking for. It requires that I hard code the
          > argument in the callback declaration. I want to be able to send a
          > dynamic argument during the startRequest call:
          >
          > AjaxObject.startRequest(myarg)
          >
          > ...and have myarg available in the success handler. I still haven't
          > figured out how to do this.

          Define the property *argument* within startRequest. For example:

          var AjaxObject = {
          handleSuccess:function(o){
          // the alert will show 123
          alert(o.argument);
          },

          handleFailure:function(o){ alert('failed'); },

          startRequest:function(myarg) {
          // define argument here
          callback.argument = myarg
          var request = YAHOO.util.Connect.asyncRequest(
          'GET',
          'http://ue.corp.yahoo.com/tsha/php/get.php',
          callback
          );
          }
          };

          var callback = {
          success:AjaxObject.handleSuccess,
          failure:AjaxObject.handleFailure
          };

          // send a 'myarg' argument to the start function
          AjaxObject.startRequest(123);
        Your message has been successfully submitted and would be delivered to recipients shortly.