Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,994
    Thanks
    120
    Thanked 76 Times in 76 Posts

    ajax within object, undefined

    Edit: digged out some old code , added blue lines, explanation ?

    Code:
    comments = new Comments("some text")
    
    function Comments(jsp)
    {
      this.jsp = jsp;
      var that = this;
      this.save = function(obj)
      {
        alert(this.jsp);// pops out 'some text'  
        ....
        ///call ajax ... catch response in catch_save 
        
      }
    
      this.catch_save = function()
      {
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
        {
           alert(this.jsp);// pops out undefined  
           alert(that.jsp);// pops out 'some text'    }
      }
    
      
    }
    how come that there is undefined ?
    Last edited by BubikolRamios; 11-11-2010 at 05:37 PM.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #2
    Regular Coder
    Join Date
    Jan 2006
    Posts
    568
    Thanks
    6
    Thanked 84 Times in 84 Posts
    this refers to the current object so its value is dependent on where it's used. catch_save isn't called with the new keyword so this refers to nothing. Obviously if you did var inst=new catch_save();, this would refer to inst, but that's not what you want...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •