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:
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!!!
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!!!