📄 ajax_server.asp@output=print
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>AJAX - Request a Server</title>
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="Keywords" content="xml,tutorial,html,dhtml,css,xsl,xhtml,javascript,asp,ado,vbscript,dom,sql,colors,soap,php,authoring,programming,training,learning,beginner's guide,primer,lessons,school,howto,reference,examples,samples,source code,tags,demos,tips,links,FAQ,tag list,forms,frames,color table,w3c,cascading style sheets,active server pages,dynamic html,internet,database,development,Web building,Webmaster,html guide" />
<meta name="Description" content="Free HTML XHTML CSS JavaScript DHTML XML DOM XSL XSLT RSS AJAX ASP ADO PHP SQL tutorials, references, examples for web building." />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "../../https@ssl./default.htm" : "../../www./default.htm");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-3855518-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>
</head>
<body>
<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>
<h1>AJAX - Request a Server</h1>
<a href="ajax_xmlhttprequest.asp"><img border="0" src="../images/btn_previous.gif" width="100" height="20" alt="Previous" /></a>
<a href="ajax_serverscript.asp"><img border="0" src="../images/btn_next.gif" width="100" height="20" alt="Next" /></a>
<hr />
<h2>AJAX - Sending a Request to the Server</h2>
<p>To send off a request to the server, we use the open() method and the send()
method.</p>
<p>The open() method takes three arguments. The first argument defines which
method to use when sending the request (GET or POST). The second argument
specifies the URL of the server-side script. The third argument specifies that
the request should be handled asynchronously. The send() method sends the request off to the
server. If we assume that the HTML and ASP file are in the same directory, the code
would be: </p>
<table class="ex" width="100%" border="1" id="table10"><tr><td>
<pre>xmlHttp.open("GET","time.asp",true);
xmlHttp.send(null);</pre>
</td></tr></table>
<p>Now we must decide when the AJAX function should be executed. We will let the
function run "behind the scenes" when the user types something in the username
text field:</p>
<table class="ex" width="100%" border="1" id="table11"><tr><td>
<pre><form name="myForm">
Name: <input type="text"
onkeyup="ajaxFunction();" name="username" />
Time: <input type="text" name="time" />
</form></pre>
</td></tr></table>
<p>Our updated AJAX-ready "testAjax.htm" file now looks like this:</p>
<table class="ex" width="100%" border="1" id="table12"><tr><td>
<pre><html><br /><body></pre>
<pre><script type="text/javascript"><br />function ajaxFunction()
{<br />var xmlHttp;
try
{<br /> // Firefox, Opera 8.0+, Safari<br /> xmlHttp=new XMLHttpRequest();<br /> }
catch (e)
{<br /> // Internet Explorer<br /> try
{<br /> xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");<br /> }
catch (e)
{<br /> try
{<br /> xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");<br /> }
catch (e)
{<br /> alert("Your browser does not support AJAX!");<br /> return false;<br /> }<br /> }<br /> }
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.myForm.time.value=xmlHttp.responseText;
}
}
xmlHttp.open("GET","time.asp",true);
xmlHttp.send(null);<br /> }<br /></script></pre>
<pre><form name="myForm">
Name: <input type="text"
onkeyup="ajaxFunction();" name="username" />
Time: <input type="text" name="time" />
</form></pre>
<pre></body>
</html></pre>
</td></tr></table>
<p>The next chapter makes our AJAX application complete with the "time.asp"
script.</p>
<hr />
<a href="ajax_xmlhttprequest.asp"><img border="0" src="../images/btn_previous.gif" width="100" height="20" alt="Previous" /></a>
<a href="ajax_serverscript.asp"><img border="0" src="../images/btn_next.gif" width="100" height="20" alt="Next" /></a>
<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -