travisbrown
Technical User
- Dec 31, 2001
- 1,016
I'm trying to return a string value from a remote call to a variable. I'm getting 'undefined' and I'm not sure why. Any ideas? The remote page is a simple text string that returns correctly when called up directly.
Code:
<script type="text/javascript">
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}
function getString(page) {
var http = createRequestObject();
http.open( 'get', page , true);
http.onreadystatechange = function(){
if ( http.readyState == 4 ) {
var response = responseText;
return response;
http = null;
}
};
http.send(null);
}
function test() {
alert(getString('test.asp'));
};
</script>
<a href="javascript:test();">test</a>