Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  8] [ 7]  / answers: 1 / hits: 24914  / 14 Years ago, wed, october 13, 2010, 12:00:00

Does anyone know how to set up set up a default action for when a ServerXMLHTTP request times out? I'm using setTimeouts() to set the time out options according to the MSDN site.



Ideally I would like to initialize the request again from the beginning or refresh the page should it time out.



I'm using classic asp and jscript.



Here's my request:



function serverXmlHttp(url) {
var serverXmlHttp;
serverXmlHttp = Server.CreateObject(Msxml2.ServerXMLHTTP.6.0);

// set time out options
serverXmlHttp.setTimeouts(15000,15000,15000,15000);

// does not work
// serverXmlHttp.ontimeout(Response.Write(page has timed out));

serverXmlHttp.open(GET, url, false);
serverXmlHttp.send();

if (serverXmlHttp.readyState == 4) {
return serverXmlHttp.responseText;
}
}

More From » asp-classic

 Answers
5

Figured it out. I just need to use a try/catch statement.



function serverXmlHttp(url) {

try {
var serverXmlHttp;
serverXmlHttp = Server.CreateObject(Msxml2.ServerXMLHTTP.6.0);

// set time out options
serverXmlHttp.setTimeouts(15000,15000,15000,15000);

serverXmlHttp.open(GET, url, false);
serverXmlHttp.send();

if (serverXmlHttp.readyState == 4) {
return serverXmlHttp.responseText;
}
catch(error) {
// whatever I want to happen if there's an error
Response.Write(Sorry, your request has timed out);
}

}

[#95334] Monday, October 11, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hallie

Total Points: 503
Total Questions: 114
Total Answers: 103

Location: Iraq
Member since Fri, Jun 5, 2020
4 Years ago
;