[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

10/12/2009 at 01:40AM PDT, ID: 24803900 | Points: 500
[x]
Attachment Details

How do i make these two ajax responses completely seperate...

Asked by Laride in Asynchronous Javascript and XML (AJAX), Active Server Pages (ASP), Miscellaneous Web Development

Tags: Ajax, Asp, javascript, wscript.shell

Hi, wondered if someone can help me...

i have a page, which i need to dynamically update using xmlhttp object.

The ajax page itself is running a wscript.shell Ping command, to check certain servers are responding...  The Problem: As each ping command can take quite a time to resolve (if the server is off line) i need each command to happen independantly. So i can run an onLoad function, and each result will be returned as and when the result comes back. Due to the amount of pings, they cannot be sequential (one function after another)

The code i have so far creates two objects, and runs 2 commands.... yet i get each response 3 seconds after the last, they appear to be running sequencially.

Im pulling my hair out on this one. i cant see where the issue is. surely i can run multiple requests at once? and surely the same ajax page (with a different query string) can be accessed simultaneusly?

Please help!

Cheers
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
ajaxPing.asp
 
<%
 
response.Expires = -1
 
	Set ShellObject = CreateObject("WScript.Shell")
	Set CommandObject = ShellObject.Exec("ping " & Request("Address"))
	PingResult = CommandObject.StdOut.Readall()
	
	
	If InStr(PingResult,"TTL=") > 0 Then 
		MyResponse = "Success"
	Else
		MyResponse = "Fail"
	End If
	
	Response.Write(MyResponse & "<br /><br />" & Replace(PingResult, vbCrLf , "<br>"))
 
%>
 
Main Page :
 
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
 
<body>
 
 
<script>
ajaxFunctionRef = 0
 
 
	function RunPing(SiteAddr) {
	SaveURL = "ajaxPing.asp?address="+SiteAddr
	
	var xmlHttp;
  	try {xmlHttp=new XMLHttpRequest();}
  		catch (e) { try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
    		catch (e) { try {xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");} 
				catch (e) { alert("Your browser does not support AJAX!");        
				return false;
		        }}}  
	xmlHttp.onreadystatechange=function()
  	 	{ if(xmlHttp.readyState==4) {
			// Ajax Response Code - use xmlHttp.responseText for returned response.Write() commands
			try {
				document.getElementById("output").innerHTML = xmlHttp.responseText
			
			} catch (e) {alert('Sorry, there is an error in the AJAX Response.\n\nError Description : ' + e.description);
							document.getElementById("output").innerHTML = xmlHttp.responseText;
							}
		}}//End Response Function');
	xmlHttp.open("GET",SaveURL,true);
    xmlHttp.send(null);  
	}
	
	
	function RunPing2(SiteAddr) {
	SaveURL = "ajaxPing.asp?address="+SiteAddr
	
	var xmlHttp2;
  	try {xmlHttp2=new XMLHttpRequest();}
  		catch (e) { try { xmlHttp2=new ActiveXObject("Msxml2.XMLHTTP");}
    		catch (e) { try {xmlHttp2=new ActiveXObject("Microsoft.XMLHTTP");} 
				catch (e) { alert("Your browser does not support AJAX!");        
				return false;
		        }}}  
	xmlHttp2.onreadystatechange=function()
  	 	{ if(xmlHttp2.readyState==4) {
			// Ajax Response Code - use xmlHttp.responseText for returned response.Write() commands
			try {
				document.getElementById("output").innerHTML = xmlHttp2.responseText
			
			} catch (e) {alert('Sorry, there is an error in the AJAX Response.\n\nError Description : ' + e.description);
							document.getElementById("output").innerHTML = xmlHttp2.responseText;
							}
		}}//End Response Function');
	xmlHttp2.open("GET",SaveURL,true);
    xmlHttp2.send(null);  
	}
</script>
<div style="width:500px; height:200px; border:1px solid #cccccc;">
<div style="margin:3px; float:left; padding:4px; border:1px solid #cccccc" onclick="RunPing('192.168.1.1');RunPing2('localhost');">Ping</div>
</div>
<div id="output"></div>
</body>
</html>
[+][-]10/12/09 04:37 AM, ID: 25550263

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/12/09 06:36 AM, ID: 25551083

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/12/09 08:11 AM, ID: 25551915

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/12/09 08:12 AM, ID: 25551931

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-91 - Hierarchy / EE_QW_3_20080625