⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ajax_source.asp@output=print

📁 W3Schools tutorial..web designing
💻 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 Source Code to Suggest Example</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>

<script src="clienthint.js" type="text/javascript"></script> 
<style>
<!--
div.Section1
	{page:Section1;}
-->
</style>
</head>
<body>

<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>

<h1>AJAX Suggest Source Code</h1>
<a href="ajax_example_suggest.asp"><img border="0" src="../images/btn_previous.gif" width="100" height="20" alt="Previous" /></a>
<a href="ajax_database.asp"><img border="0" src="../images/btn_next.gif" width="100" height="20" alt="Next" /></a>
<hr />
<h2>AJAX Source Code to Suggest Example</h2>
<p>The source code below belongs to the AJAX example on the previous page.</p>
<p>You can copy and paste it, and try it yourself.</p>
<hr />
<h2>The AJAX HTML Page</h2>

<p>This is the HTML page. It contains a simple HTML form and a link to a 
JavaScript.</p>

<table class="ex" width="100%" border="1" id="table1"><tr><td>
<pre>&lt;html&gt;
&lt;head&gt;
&lt;script src=&quot;clienthint.js&quot;&gt;&lt;/script&gt; 
&lt;/head&gt;
&lt;body&gt;</pre>
<pre>&lt;form&gt; 
First Name:
&lt;input type=&quot;text&quot; id=&quot;txt1&quot;
onkeyup=&quot;showHint(this.value)&quot;&gt;
&lt;/form&gt;</pre>
<pre>&lt;p&gt;Suggestions: &lt;span id=&quot;txtHint&quot;&gt;&lt;/span&gt;&lt;/p&gt; </pre>
<pre>&lt;/body&gt;
&lt;/html&gt;</pre>
</td></tr></table>

<p>
The JavaScript code is listed below.</p>

<hr />
<h2>The AJAX JavaScript</h2>

<p>This is the JavaScript code, stored in the file &quot;clienthint.js&quot;:</p>

<table class="ex" width="100%" border="1" id="table2"><tr><td>
<pre>var xmlHttp

function showHint(str)
{
if (str.length==0)
  { 
  document.getElementById(&quot;txtHint&quot;).innerHTML=&quot;&quot;;
  return;
  }
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert (&quot;Your browser does not support AJAX!&quot;);
  return;
  } 
var url=&quot;gethint.asp&quot;;
url=url+&quot;?q=&quot;+str;
url=url+&quot;&amp;sid=&quot;+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open(&quot;GET&quot;,url,true);
xmlHttp.send(null);
} 

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById(&quot;txtHint&quot;).innerHTML=xmlHttp.responseText;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject(&quot;Msxml2.XMLHTTP&quot;);
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);
    }
  }
return xmlHttp;
}</pre>
</td></tr></table>
<br />
<hr />

<h2>The AJAX Server Page - ASP and PHP</h2>

<p><b>There is no such thing as an AJAX server. AJAX pages can be served by any internet server.</b><br />
</p>

<p>The server page called by the JavaScript in the example from the previous 
chapter is a simple ASP file called &quot;gethint.asp&quot;.</p>
<p>Below we have listed two examples of the server page code, one written in ASP 
and one in PHP. </p>
<hr />

<h2>AJAX ASP Example</h2>
<p>The code in the &quot;gethint.asp&quot; page is written in VBScript for an Internet Information Server (IIS). 
It just checks an array of names and returns the corresponding names to the 
client:</p>

<table class="ex" width="100%" border="1" id="table5"><tr><td>
<pre>&lt;%
response.expires=-1
dim a(30)
'Fill up array with names
a(1)=&quot;Anna&quot;
a(2)=&quot;Brittany&quot;
a(3)=&quot;Cinderella&quot;
a(4)=&quot;Diana&quot;
a(5)=&quot;Eva&quot;
a(6)=&quot;Fiona&quot;
a(7)=&quot;Gunda&quot;
a(8)=&quot;Hege&quot;
a(9)=&quot;Inga&quot;
a(10)=&quot;Johanna&quot;
a(11)=&quot;Kitty&quot;
a(12)=&quot;Linda&quot;
a(13)=&quot;Nina&quot;
a(14)=&quot;Ophelia&quot;
a(15)=&quot;Petunia&quot;
a(16)=&quot;Amanda&quot;
a(17)=&quot;Raquel&quot;
a(18)=&quot;Cindy&quot;
a(19)=&quot;Doris&quot;
a(20)=&quot;Eve&quot;
a(21)=&quot;Evita&quot;
a(22)=&quot;Sunniva&quot;
a(23)=&quot;Tove&quot;
a(24)=&quot;Unni&quot;
a(25)=&quot;Violet&quot;
a(26)=&quot;Liza&quot;
a(27)=&quot;Elizabeth&quot;
a(28)=&quot;Ellen&quot;
a(29)=&quot;Wenche&quot;
a(30)=&quot;Vicky&quot;</pre>
<pre>'get the q parameter from URL
q=ucase(request.querystring(&quot;q&quot;))</pre>
<pre>'lookup all hints from array if length of q&gt;0
if len(q)&gt;0 then
  hint=&quot;&quot;
  for i=1 to 30
    if q=ucase(mid(a(i),1,len(q))) then
      if hint=&quot;&quot; then
        hint=a(i)
      else
        hint=hint &amp; &quot; , &quot; &amp; a(i)
      end if
    end if
  next
end if</pre>
<pre>'Output &quot;no suggestion&quot; if no hint were found
'or output the correct values
if hint=&quot;&quot; then 
  response.write(&quot;no suggestion&quot;)
else
  response.write(hint)
end if
%&gt;</pre>
</td></tr></table>
<br />
<hr />

<h2>AJAX PHP Example</h2>

<p>The code above rewritten in PHP.</p>
<p><b>Note:</b> To run the entire example in PHP, remember to change the value 
of the url variable in &quot;clienthint.js&quot; from &quot;gethint.asp&quot; to &quot;gethint.php&quot;.</p>
<h3>PHP Example</h3>

<table class="ex" width="100%" border="1" id="table6"><tr><td>
<pre>&lt;?php
<font face="Courier New" size="2"><span lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><span class="default">header</span><span class="keyword">(</span><span class="string">&quot;Cache-Control: no-cache, must-revalidate&quot;</span><span class="keyword">);
</span></span><span lang="EN-GB" style="font-size: 10pt; font-family: Courier New"><span class="keyword"> </span><span class="comment">// Date in the past</span></span><span lang="EN-GB" style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><span class="keyword">
</span><span class="default">header</span><span class="keyword">(</span><span class="string">&quot;Expires: Mon, 26 Jul 1997 05:00:00 GMT&quot;</span><span class="keyword">);</span>
</span></font>
// Fill up array with names
$a[]=&quot;Anna&quot;;
$a[]=&quot;Brittany&quot;;
$a[]=&quot;Cinderella&quot;;
$a[]=&quot;Diana&quot;;
$a[]=&quot;Eva&quot;;
$a[]=&quot;Fiona&quot;;
$a[]=&quot;Gunda&quot;;
$a[]=&quot;Hege&quot;;
$a[]=&quot;Inga&quot;;
$a[]=&quot;Johanna&quot;;
$a[]=&quot;Kitty&quot;;
$a[]=&quot;Linda&quot;;
$a[]=&quot;Nina&quot;;
$a[]=&quot;Ophelia&quot;;
$a[]=&quot;Petunia&quot;;
$a[]=&quot;Amanda&quot;;
$a[]=&quot;Raquel&quot;;
$a[]=&quot;Cindy&quot;;
$a[]=&quot;Doris&quot;;
$a[]=&quot;Eve&quot;;
$a[]=&quot;Evita&quot;;
$a[]=&quot;Sunniva&quot;;
$a[]=&quot;Tove&quot;;
$a[]=&quot;Unni&quot;;
$a[]=&quot;Violet&quot;;
$a[]=&quot;Liza&quot;;
$a[]=&quot;Elizabeth&quot;;
$a[]=&quot;Ellen&quot;;
$a[]=&quot;Wenche&quot;;
$a[]=&quot;Vicky&quot;;</pre>
<pre>//get the q parameter from URL
$q=$_GET[&quot;q&quot;];</pre>
<pre>//lookup all hints from array if length of q&gt;0
if (strlen($q) &gt; 0)
{
  $hint=&quot;&quot;;
  for($i=0; $i&lt;count($a); $i++)
  {
  if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
    {
    if ($hint==&quot;&quot;)
      {
      $hint=$a[$i];
      }
    else
      {
      $hint=$hint.&quot; , &quot;.$a[$i];
      }
    }
  }
}

// Set output to &quot;no suggestion&quot; if no hint were found
// or to the correct values
if ($hint == &quot;&quot;)
{
$response=&quot;no suggestion&quot;;
}
else
{
$response=$hint;
}

//output the response
echo $response;
?&gt;</pre>
</td></tr></table>
<br />
<hr />

<a href="ajax_example_suggest.asp"><img border="0" src="../images/btn_previous.gif" width="100" height="20" alt="Previous" /></a>
<a href="ajax_database.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 + -