/    Sign up×
Community /Pin to ProfileBookmark

HttpRequest failing

Hi, I’m having trouble with a HttpRequest. I used the code below for the request and I ran them off a webserver but I got the catch(errv) error as an undefined error in Firefox, and got a blank page in IE. The firefox error console doesn’t show any errors. I am positive the URL I used was correct because it works when I type it into my browser.

Any help is really appreciated. I am new at this and have a lot to learn. Thanks!

[CODE]var request = null;
/* Initialize a Request object that is already constructed */
function initReq(reqType,url,bool,respHandle){
try{
/* Specify the function that will handle the HTTP response */
request.onreadystatechange=respHandle;
request.open(reqType,url,bool);
//if the reqType parameter is POST, then the
//5th argument to the function is the POSTed data
if(reqType.toLowerCase() == “post”) {
request.setRequestHeader(“Content-Type”,
“application/x-www-form-urlencoded; charset=UTF-8”);
request.send(arguments[4]);
} else {
request.send(null);
}

} catch (errv) {
alert(
“The application cannot contact “+
“the server at the moment. “+
“Please try again in a few seconds.n”+
“Error detail: “+errv.message);
}
}
/* Wrapper function for constructing a Request object.
Parameters:
reqType: The HTTP request type such as GET or POST.
url: The URL of the server program.
asynch: Whether to send the request asynchronously or not.
respHandle: The name of the function that will handle the response.
Any fifth parameters represented as arguments[4] are the data a
POST request is designed to send. */
function httpRequest(reqType,url,asynch,respHandle){
//Mozilla-based browsers
if(window.XMLHttpRequest){
request = new XMLHttpRequest();
} else if (window.ActiveXObject){
request=new ActiveXObject(“Msxml2.XMLHTTP”);
if (! request){
request=new ActiveXObject(“Microsoft.XMLHTTP”);
}
}
//Very unlikely, but we test for a null request
//if neither ActiveXObject was initialized
if(request) {
//if the reqType parameter is POST, then the
//5th argument to the function is the POSTed data
if(reqType.toLowerCase() != “post”) {
initReq(reqType,url,asynch,respHandle);
} else {
//the POSTed data
var args = arguments[4];
if(args != null && args.length > 0){
initReq(reqType,url,asynch,respHandle,args);
}
}
} else {
alert(“Your browser does not permit the use of all “+
“of this application’s features!”);}
}
[/CODE]

[CODE]var url = “http://xoap.weather.com/weather/local/”+
locationId+”?cc=*&dayf=2&prod=xoap&par=”+
partId+”&key=”+licId;
httpRequest(“GET”,url,true,handleResponse);[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Dec 23.2007 — The XMLHttpRequest only works off the same domain. So that means your page has to be sitting at http://xoap.weather.com

Eric
×

Success!

Help @sayeo 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,
)...