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

Re: [ydn-javascript] Re: Keeping connections in an object.

Expand Messages
  • Len Coonan
    Brilliant. Thank you so much. I didn t even think of the location of the defn. I have noticed another request for an example of using this code. Would you
    Message 1 of 6 , Mar 22, 2006
    • 0 Attachment
      Brilliant. Thank you so much. I didn't even think of the location of
      the defn. I have noticed another request for an example of using this
      code. Would you agree that

      *** begin example ***
      function connectThing(pDataSource){
      this.dataSource = pDataSource;
      this.loadData = function(){
      this.cObj = YAHOO.util.Connect.asyncRequest('GET', this.dataSource,
      this.loadCallBack, null);
      };
      this.loadSuccess = function(o){
      ... handle your data here.
      };
      this.loadFail = function(o){
      ... handle your error here.
      };
      // the callback function must be defined after the declarations of the
      functions.
      this.loadCallBack = {success:this.loadSuccess,failure:this.loadFail,
      scope:this};
      }

      $loadObj = new connectThing('http://my.domain/data.html');
      $loadObj->loadData();
      *** end example ***

      Thomas S. Sha wrote:

      > --- In ydn-javascript@yahoogroups.com, Len Coonan <len@...> wrote:
      > >
      > > Sorry, defined in another included script as follows
      > > function fieldObj(dataName, dataType, displayName){
      > > this.dataName = dataName;
      > > this.dataType = dataType;
      > > this.displayName = displayName;
      > > }
      >
      > Try the following example. I moved your callback declaration, so that
      > it is defined after loadSuccess is defined.
      >
      > Regards,
      > Thomas
      >
      > *** begin example ***
      >
      > function fieldObj(dataName, dataType, displayName){
      > this.dataName = dataName;
      > this.dataType = dataType;
      > this.displayName = displayName;
      > }
      >
      > function listComponent(tableId){
      > this.tableId = tableId;
      > this.fieldArray = new Array();
      > this.addField = function(dataName, dataType, displayName)
      > {
      > this.fieldArray.push(new fieldObj(dataName, dataType, displayName));
      > };
      >
      > this.loadSuccess = function(o){
      > alert(o.responseText);
      > //loadContactList(o.responseText);
      > }
      > this.loadFailure = function(o){}
      >
      > this.callback = { success:this.loadSuccess, scope:this};
      > this.loadData = function(){
      > this.cObj = YAHOO.util.Connect.asyncRequest
      > ('GET',this.sourceData,this.callback,null);
      > };
      > }
      >
      > var contacts = new listComponent('ContactTable');
      >
      > contacts.sourceData = "/xml.php";
      > contacts.addField('NAME','str','Name');
      > contacts.addField('SEX','str','Sex');
      > contacts.addField('AGE','num','Age');
      > contacts.addField('WEIGHT','num','Weight');
      > contacts.loadData();
      >
      >
      >
      >
      >
      > ------------------------------------------------------------------------
      > YAHOO! GROUPS LINKS
      >
      > * Visit your group "ydn-javascript
      > <http://groups.yahoo.com/group/ydn-javascript>" on the web.
      >
      > * To unsubscribe from this group, send an email to:
      > ydn-javascript-unsubscribe@yahoogroups.com
      > <mailto:ydn-javascript-unsubscribe@yahoogroups.com?subject=Unsubscribe>
      >
      > * Your use of Yahoo! Groups is subject to the Yahoo! Terms of
      > Service <http://docs.yahoo.com/info/terms/>.
      >
      >
      > ------------------------------------------------------------------------
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.