Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

goofy function question

Status
Not open for further replies.

timgerr

IS-IT--Management
Jan 22, 2004
364
US
hey all I have a problem that is hard to get into. Here is the situation that I have... I have a function that data is returned into, lets create a test case
Code:
function testme(data, ioArgs)
{
     alert(data.something);
}
I would like to get the value if data.something out of the function with out calling (because I cant)
Code:
var outMe = test(data, ioArgs);

is there a way to get the data out of test me without calling another function?

thanks,
timgerr



-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!

 
Fake code = fake answers.
Real code = real answers.

How about being less cryptic and showing what you're REALLY doing?

Lee
 
ok,
I have created a jodo ajax call object
Code:
ajaxCall = var {
post : function (URL,returnData,objectPostData,dataFormat)
		{
			var insert = new Object();
			insert['url'] = URL;
			insert['format'] = dataFormat;
			var eventsubmit = ({
				url: insert['url'],
				content: objectPostData,
				handleAs: insert['format'],
			    timeout:5000,
			    handle: function(response, ioArgs){
			    //This function handles the response.
			    //Inside this function, the "this" variable
			    //will be the object used as the argument to the dojo.xhrGet() call.
			    if(response instanceof Error){
			    	if(response.dojoType == "cancel"){
			        	//The request was canceled by some other JavaScript code.
			            console.debug("Request canceled.");
			        }else if(response.dojoType == "timeout"){
			        	//The request took over 5 seconds to complete.
			            console.debug("Request timed out.");
			        }else{
			        	//Some other error happened.
			            console.error(response);
			        }
			    }else{
				    //Success.Since original call wanted the response handled
				    //as text (handleAs: "text"), response will be a text string.
//				    console.debug("Successful server response: " + response);
			
					//ioArgs is an object with some useful properties on it.
			        //For instance, for XMLHttpRequest calls, ioArgs.xhr is the
			        //XMLHttpRequest that was used for the call.
			        //alert("HTTP status code: ", ioArgs.xhr);
					return(response);
			        
			    }
			    //If you think there could be other callback handlers registered with this deferred, then
			    //return response to propagate the same response to other callback handlers. Otherwise,
			    //the error callbacks may be called in the success case.
			    return response;
			}
			});
			var def = dojo.xhrPost(eventsubmit);
			def.addCallback(returnData);
	}
};
you will see that the post ajaxCall.post has uses these parameters
Code:
post : function (URL,returnData,objectPostData,dataFormat)
I give the object a url, a location to send the returned data, like a function or an object. I have to create a post data object that will handel the post data and how I want to data returned, test or json string.

so I create this function that the data will go to
Code:
function testme(data, ioArgs)
{
     alert(data.something);
}
and the json string will go there. I want to take this returned data and use it as a global variable, so I have to get it out of the function. usually (i thing) I would call the object like this
Code:
var return = ajaxCall.post(URL,returnData,objectPostData,dataFormat)
but because I am using the dojo framework I am unable to use that call.

I was wondering if there was another way to get data out of a function without calling another function.

timgerr

-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!

 
This really isn't a ajax question, it is a javascsript question. I want to get data out of a function. The only reason why I posted my code was to satisfy trollacious.

Thanks,
timgerr

-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!

 
I can't really understand your question. I sort of understand what you mean but don't understand your problem. I don't think javascript lets you return data from a function with out a return statement and that would require you to call a function. You can use a global variable and assign it's value to whatever value you need that lives in the scope of your function. Why exactly you can not call a function? or add a method? to your object is not clear. I'm pretty sure dojo extends extends javascript functionality and can not alter how objects are defined and called.

so for example
dataObj = {
something : "somedata",
rSomething : function(){alert(this.something)}
};

dataObj.rSomething();

and you can also
alert(dataObj.something)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top