/    Sign up×
Community /Pin to ProfileBookmark

problem with returning value

I’m using ajax to on one of my pages and using the function below to get a pages response. I want to be able to have the function get_page_response return the value of the page response. However, I cant figure out a way to do it since the returning xmlHttp.responseText in the onreadystatechange method. I was hoping to be able to do something like get_page_response.return(xmlHttp.responseText), but that doesn’t work, any ideas?

[CODE]
function get_page_response(url){
var xmlHttp;
try{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e){
// Internet Explorer
try{
xmlHttp=new ActiveXObject(“Msxml2.XMLHTTP”);
}
catch (e){
try{
xmlHttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
catch (e){
//browser does not support AJAX
return false;
}
}
}
xmlHttp.onreadystatechange = function(){
return xmlHttp.responseText;
}
xmlHttp.open(“GET”,url, true);
xmlHttp.send(null);
}
[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@mrhooJun 05.2007 — xmlHttp.onreadystatechange = function(){

return xmlHttp.responseText;

}[/QUOTE]


THis will return as soon as the ready state changes, but there is no responseText until the readystate is 3- and it is not complete until readystate is 4.

But there is no longer any caller to return anything to- send the text to another function, or define the handler here.
×

Success!

Help @twooton spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...