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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to return a functions

Status
Not open for further replies.

timgerr

IS-IT--Management
Jan 22, 2004
364
US
Hey all, I am using prototype.js to create a ajax function and I am havin troubles returning the data, here is what I mean:
Code:
<html>
	<head>
		<script type="text/javascript" src="../Prototype/prototype.js"></script>
		<script type="text/javascript">
	//			function Ajax(sURL)	
//					{
					
function SendData(urlString,url)
{
				var opt = {
				    // Use POST
				    method: 'post',
				    // Send this lovely data
				    //postBody: 'p1=firsttime',
					postBody: urlString,
				    // Handle successful response
				    onSuccess: function(t) {
						// Sending the responcd to be parsed and entered in the correct places
				        alert("From withing the function ** " + t.responseText + " **");  // <---- This works
						
						return(t.responseText);  //  <-----------------Return This data
				    },
				    // Handle 404
				    on404: function(t) {
				        alert('Error 404: location "' + t.statusText + '" was not found.');
				    },
				    // Handle other errors
				    onFailure: function(t) {
				        alert('Error ' + t.status + ' -- ' + t.statusText);
				    }
				}

				new Ajax.Request(url, opt);
				
}		
		</script>
		<script type="text/javascript">
			function doME()
			{
				var back = SendData('lala','[URL unfurl="true"]http://miys02ae211935l/learn/dhtmlwindow/showme.php');[/URL]
				alert(back);  // < ---- alerts undefined
			}		
		</script>

	</head>
	<body>
		<button onclick="doME()">DoMe</button>
		<div id="putHere">This will change</div>
	</body>
</html>

How can I return the data, the alert part works fine, but when I return the data I get an alert box saying undefined.

Thanks,
-T

-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top