0335342e00
First Draft of the Example Files
68 lines
1.6 KiB
HTML
68 lines
1.6 KiB
HTML
<!DOCTYPE html>
|
|
<html> <!-- urlpost.html -->
|
|
<head>
|
|
<title>Asynchronous Communication Example</title>
|
|
</head>
|
|
<body style='text-align:center'>
|
|
<h1>Loading a web page into a DIV</h1>
|
|
<div id='info'>This sentence will be replaced</div>
|
|
|
|
<script>
|
|
params = "url=news.com"
|
|
request = new asyncRequest()
|
|
|
|
request.open("POST", "urlpost.php", true)
|
|
request.setRequestHeader("Content-type",
|
|
"application/x-www-form-urlencoded")
|
|
request.setRequestHeader("Content-length", params.length)
|
|
request.setRequestHeader("Connection", "close")
|
|
|
|
request.onreadystatechange = function()
|
|
{
|
|
if (this.readyState == 4)
|
|
{
|
|
if (this.status == 200)
|
|
{
|
|
if (this.responseText != null)
|
|
{
|
|
document.getElementById('info').innerHTML =
|
|
this.responseText
|
|
}
|
|
else alert("Communication error: No data received")
|
|
}
|
|
else alert( "Communication error: " + this.statusText)
|
|
}
|
|
}
|
|
|
|
request.send(params)
|
|
|
|
function asyncRequest()
|
|
{
|
|
try
|
|
{
|
|
var request = new XMLHttpRequest()
|
|
}
|
|
catch(e1)
|
|
{
|
|
try
|
|
{
|
|
request = new ActiveXObject("Msxml2.XMLHTTP")
|
|
}
|
|
catch(e2)
|
|
{
|
|
try
|
|
{
|
|
request = new ActiveXObject("Microsoft.XMLHTTP")
|
|
}
|
|
catch(e3)
|
|
{
|
|
request = false
|
|
}
|
|
}
|
|
}
|
|
return request
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|