Results 1 to 3 of 3
  1.    #1  
    I am having a problem with Callback methods in Javascript. I am not fully understanding them I think.

    I have a static method Caller.call_get() it gets passed an argument called params. In this method params is a argument that has properties that allow the callback that occurs within Caller.call_get() to propagate upwards to the object that called this static function. Caller.call_get() implementation follows:

    Code:
    Caller.call_get = function(params) {
    	try {
    		var myAjax = new Ajax.Request(url, {
    			encoding: 'UTF-8',
    			method: 'get',
    			evalJSON: true,
    			onSuccess: params.onSuccess,
    			onFailure: function() {Mojo.Log.info("Failure!");},
    			parameters: params.parameters
    		});
    	} catch (e) {
    		Mojo.Log.error("Caller.call_get exception: %j", e);
    	}
    };
    When I call Caller.call_get() I do:

    Code:
    Caller.call_get({
    	parameters: params,
    	onSuccess: Authenticator.onSuccess.bind(this),
    	onFailure: Authenticator.onFailure.bind(this) 
    });
    I expect my static Autheticator object's onSuccess function to be called. However, I get no response what-so-ever.

    Please help.
  2. drnull's Avatar
    Posts
    570 Posts
    Global Posts
    571 Global Posts
    #2  
    Code:
    Caller.call_get = function(params) {
    	try {
                    Mojo.Log.error("calling Ajax.Request(%s)", url);
    		var myAjax = new Ajax.Request(url, {
    			encoding: 'UTF-8',
    			method: 'get',
    			evalJSON: true,
    			onSuccess: function() {Mojo.Log.error("onSuccess called"); params.onSuccess(); Mojo.Log.error("onSuccess finished");},
    			onFailure: function() {Mojo.Log.error("Failure!");},
    		});
                    Mojo.Log.error("AjaxRequest finished");
    	} catch (e) {
    		Mojo.Log.error("Caller.call_get exception: %j", e);
    	}
    };
    I would try something like this to narrow down where you are having problems.
  3.    #3  
    Thanks drnull. That did not end up working exactly, I ended up adding a try/catch but I did solve the problem.

    Also, love the podcast app.

Posting Permissions