www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Rate Thread Display Modes
      #1  
    Old 02-04-2010, 10:34 AM
    Mulone Mulone is offline
    Registered User
     
    Join Date: Jan 2010
    Posts: 5
    How to access calling object in OnSuccess/OnFailure?

    Hi guys,
    I'm making this ajax call:

    Code:
    new Ajax.Request(url, {
    		   method: 'get',
    		   onSuccess: function(transport) {
    		       this.contextReady = true;
    		       
    		   },
    	   	   onFailure: function(transport) {
    		        this.contextReady = false;
    		   }
    			   
    	   });
    from a JS object containig contextReady. The problem is that this within the OnSuccess is not the class but something else (e.g. a window).
    How can I update the right this.contextReady?

    Thanks for any hints!
    Reply With Quote
      #2  
    Old 02-04-2010, 11:56 AM
    astupidname astupidname is offline
    Registered User
     
    Join Date: Oct 2008
    Location: U.S.
    Posts: 654
    Create a variable reference to the 'this' object:
    Code:
    var myObj = {
        contextReady : false,
        makeRequest : function (url) {
            var obj = this; //holder to reference myObj's 'this'
            new Ajax.Request(url, {
                method: 'get',
                onSuccess: function(transport) {
                    obj.contextReady = true;
                },
                onFailure: function(transport) {
                    obj.contextReady = false;
                }     
            });
        }
    };
    Reply With Quote
    Reply

    Bookmarks

    Tags
    ajax, onfailure, onsuccess


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 01:12 PM.



    Acceptable Use Policy

    Internet.com
    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.