S
SteveYoungTbird
I am calling the function autoPost() with:
heights = autoPost(hundredMeters);
alert(heights)
function autoPost(points) {
var req, reply,
data = "latlng=" + points ;
if(window.XMLHttpRequest) req = new XMLHttpRequest();
else if (window.ActiveXObject) req = new
ActiveXObject(Microsoft.XMLHTTP);
req.onreadystatechange = function(){
if(req.readyState == 4){
if(req.status == 200){
reply = req.responseText;
alert(reply);
return reply;
}
else {
alert("Error: returned status code " + req.status + " "
+ req.statusText);
}
}
};
req.open("POST", "some.php", true);
req.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
req.send(data);
};
The alert(reply) in the function autoPost shows the correct data but the
alert(heights) in the calling function shows "undefined". Using:
reply = eval(req.responseText);
gives an evaluated array for alert(reply) but still "undefined" for
alert(heights).
How can I pass the returned POST data to another function?
heights = autoPost(hundredMeters);
alert(heights)
function autoPost(points) {
var req, reply,
data = "latlng=" + points ;
if(window.XMLHttpRequest) req = new XMLHttpRequest();
else if (window.ActiveXObject) req = new
ActiveXObject(Microsoft.XMLHTTP);
req.onreadystatechange = function(){
if(req.readyState == 4){
if(req.status == 200){
reply = req.responseText;
alert(reply);
return reply;
}
else {
alert("Error: returned status code " + req.status + " "
+ req.statusText);
}
}
};
req.open("POST", "some.php", true);
req.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
req.send(data);
};
The alert(reply) in the function autoPost shows the correct data but the
alert(heights) in the calling function shows "undefined". Using:
reply = eval(req.responseText);
gives an evaluated array for alert(reply) but still "undefined" for
alert(heights).
How can I pass the returned POST data to another function?