/    Sign up×
Community /Pin to ProfileBookmark

What’s wrong with this piece of code (using XMPHTTPRequest)?

Hi,

Below is the code. I found the onreadystatechange event handler never got triggers. Any idea?

Thx
Tao
[INDENT] function OnGreetingsCleck()
{
//Sample.Aspnet.HelloWorld.Greetings(“TaoWang”, OnGreetingsComplete);

// get HTTP request object
var request = HTTP.newRequest();
// receive message
request.onreadystatechange = function(){
var b = 4;
if(request.readystate==4)
{
if(request.status == 200)
//OnGreetingsComplete(request.responseText);
alert(“I get message”);
}

}
// send
request.open(“GET”, “http://www.msn.com”); //”http://localhost/HelloWorldWebService/HelloWorld.asmx”);
request.setRequestHeader(“User-Agent”, “XMLHttpRequest”);
request.setRequestHeader(“Accept-Language”, “en”);
request.send(null);
}[/INDENT]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@taowangauthorJan 13.2008 — I did debug into this method and verify that request object is successfully created. When request.open is called, the request.readystate did change from 0 to 1. but for some reason, the envent handler of onreadystatechange never got triggered (the line of var b=4 never got executed)
×

Success!

Help @taowang 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 6.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

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