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 5 of 5
  1. #1
    New Coder
    Join Date
    Apr 2006
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Anonymous function

    Hi guys,

    I have the following code:

    Code:
    function doServerRequest()
    {
    	this.ajaxArgs.ajaxObj = ClientObjects.createXmlHttpRequest();
    	this.checkParameters();
    	this.verifyProtocol();
    
    	try
    	{
    		var args = this.ajaxArgs;
    		var callback = this.stateChanged;
    
    		this.ajaxArgs.ajaxObj.onreadystatechange = function()
    		{
    			callback(args);
    		}
    	}
    	catch(ex)
    	{
    		throw (AJAX_EXCEPTION.AJAX_INSTATIATION_EXCEPTION);
    	}
    
    	try
    	{
    		this.ajaxArgs.ajaxObj.open(this.ajaxArgs.httpMethod, this.ajaxArgs.serverURL, this.ajaxArgs.requestMode);
    		this.ajaxArgs.ajaxObj.send(this.ajaxArgs.requestParam);
    	}
    	catch(ex)
    	{
    		throw (AJAX_EXCEPTION.AJAX_REQUEST_EXCEPTION);
    	}
    }
    How can I do this instead:

    Code:
    		this.ajaxArgs.ajaxObj.onreadystatechange = function()
    		{
    			this.stateChanged(this.ajaxArgs);
    		}
    I understand that the object does not belong to the anonymous function...

    Any help is welcome,

    MeTitus

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,350
    Thanks
    11
    Thanked 589 Times in 570 Posts
    i don't think the ;ast argument is correct, it sets the asynch mode.

    ex:
    XHRt.open(op, turl, true);

    read the ajax info at w3schools.com for more info.

  • #3
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Code:
    var ref = this;
    this.ajaxArgs.ajaxObj.onreadystatechange = function()
    		{
    			ref.stateChanged(ref.ajaxArgs);
    		}
    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #4
    New Coder
    Join Date
    Apr 2006
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by rnd me View Post
    i don't think the ;ast argument is correct, it sets the asynch mode.

    ex:
    XHRt.open(op, turl, true);

    read the ajax info at w3schools.com for more info.

    It is right my friend.

    MeTitus

  • #5
    New Coder
    Join Date
    Apr 2006
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by A1ien51 View Post
    Code:
    var ref = this;
    this.ajaxArgs.ajaxObj.onreadystatechange = function()
    		{
    			ref.stateChanged(ref.ajaxArgs);
    		}
    Eric
    Thank you very much for your help Eric.


    MeTitus


  •  

    Posting Permissions

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