Problem in ajax code like this.object is not defined

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gunjan123
    New Member
    • May 2008
    • 2

    Problem in ajax code like this.object is not defined

    Dear Friends ,

    I am new in ajax .Follwoning code give error -

    Code:
    var ajaxpack=new Object()
    ajaxpack.basedomain="http://"+window.location.hostname
    ajaxpack.ajaxobj=createAjaxObj()
    ajaxpack.filetype="txt"
    ajaxpack.addrandomnumber=0 //Set to 1 or 0. See documentation.
    
    ajaxpack.getAjaxRequest=function(url, parameters, elemid, filetype){
    ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
    if (ajaxpack.addrandomnumber==1) //Further defeat caching problem in IE?
    var parameters=parameters+"&ajaxcachebust="+new Date().getTime()
    if (this.ajaxobj){
    this.filetype=filetype
    this.ajaxobj.onreadystatechange=function()
    {
          if(this.ajaxobj.readyState==4)
            {
            document.getElementById(elemid).innerHTML=this.ajaxobj.responseText;
            }
    
    
    }
    
    this.ajaxobj.open('GET', url+"?"+parameters, true)
    this.ajaxobj.send(null)
    }
    }



    Error: this.ajaxobj has no properties
    Source File: http://localhost/ajax/ajaxroutine.js
    Line: 39

    line 39 is
    if(this.ajaxobj .readyState==4)

    i donot understand that why its give error because i am working on current object which is defined earlier .


    Gunjan
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Can I see your createAjaxObj() function?

    Mos likely you'll want to use ajaxpack.ajaxob j in place of this.ajaxobj.

    Comment

    • gunjan123
      New Member
      • May 2008
      • 2

      #3
      problem is solved when i use ajaxpack.ajaxob j in place of this.ajaxobj

      Thank you for solving my problem


      Gunjan

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        You're welcome. Glad you got it working. Post again if you have more questions.

        Comment

        Working...