By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,401 Members | 1,381 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,401 IT Pros & Developers. It's quick & easy.

My ping script get error or sth

P: 1
hi there since i am trying to code a java script for ping several server in the same page and resulting in picture of red/blue strip. Btw: i got stuck with some code that is not working ....it is the below code

[HTML]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>
<input type=button value=ping onclick=doping()><BR>
<input type=button value=ping2 onclick=doping2()>
<script>
probeurl="http://www.xxx.com";
function doping()
{
dt = new Date();

// callback function to be executed and request is complete

callback = function() {
ndt = new Date();
time = (ndt-dt)/1000+"ms";
if (obj.readyState == 4) {
if (obj.status == 200) {
alert(time);
alert(obj.responseText);
document.write("<input type=button value=ping onclick=doping();>");
document.write("<img src='blue.jpg'width='81' height='8'>");
document.write("<input type=button value=ping2 onclick=doping2();>");

} else {
alert('There was a problem with the request.');
document.write("<input type=button value=ping onclick=doping();>");
document.write("<img src='red.jpg'width='81' height='8'>");
document.write("<input type=button value=ping2 onclick=doping2();>");

}
}


}

if(window.XMLHttpRequest)
{
obj = new XMLHttpRequest();
obj.open("GET", probeurl, true);
}
else if(window.ActiveXObject)
{
obj = new ActiveXObject("Microsoft.XMLHTTP");
obj.open("GET", probeurl+"?aaa=333", true);
}

// specify callback function

obj.onreadystatechange = callback;

obj.send(null);
}
function doping2()
{
dt = new Date();
if(window.XMLHttpRequest)
{
obj = new XMLHttpRequest();
obj.open("GET", probeurl+"?aaa=333", true);
obj.send(null);
}
else if(window.ActiveXObject)
{
obj = new ActiveXObject("Microsoft.XMLHTTP");
obj.open("GET", probeurl+"?aaa=333", true);
obj.send(null);
}

ndt = new Date();
time = (ndt-dt)/1000+"ms";
alert(time);
}

</script>

</BODY>
</HTML>[/HTML]
Nov 25 '07 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
Welcome to TSDN!

You're using document.write after the page has loaded.

Either set the innerHTML of an element on the page or dynamically create these elements and append them to the body or another element.
Nov 26 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.