ASP - AJAX 与 ASP

AJAX డైనమిక్ అప్లికేషన్స్ సృష్టించడానికి ఉపయోగిస్తారు.

AJAX ASP ఉదాహరణ

దిగువ ఉదాహరణలో, వినియోగదారుడు పెట్టిన పేరుము క్రింది పేరుము పెట్టిన ప్రదేశంలో అక్షరాలను ముద్దించినప్పుడు, వెబ్ పేజీ సర్వర్తో కమ్యూనికేషన్ ఎలా జరుగుతుందో చూడండి:

ఉదాహరణ

దిగువ పేరుము పెట్టిన ప్రదేశంలో అక్షరాలను ముద్దించండి (A - Z):

పేరు:

సలహా:

మీరు స్వయంగా సోర్స్ కోడ్ ప్రయోగించండి

ఉదాహరణ వివరణ - HTML పేజీ

వినియోగదారుడు పైన పెట్టిన పేరుము క్రింది పేరుము పెట్టిన ప్రదేశంలో అక్షరాలను ముద్దించినప్పుడు, "showHint()" ఫంక్షన్ అమలు అవుతుంది. ఈ ఫంక్షన్ "onkeyup" ఇవెంట్ ద్వారా ప్రేరేపించబడుతుంది:

<!DOCTYPE html>
<html>
<head>
<script>
function showHint(str)
{
if (str.length==0)
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// IE7+, Firefox, Chrome, Opera, Safari కొరకు కోడ్
  xmlhttp=new XMLHttpRequest();
  }
else
  {// IE6, IE5 కొరకు కోడ్
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","gethint.asp?q="+str,true);
xmlhttp.send();
}
</script>
</head
<body>
<p><b>ఇన్‌పుట్ బాక్స్‌లో అంగ్ల అక్షరాలు ప్రవేశపెట్టండి:</b></p>
<form>
ప్రథమ పేరు: <input type="text" onkeyup="showHint(this.value)" size="20">
</form>
<p>సూగ్గెషన్స్: <span id="txtHint"></span></p>
</body>
</html>

సోర్స్ కోడ్ వివరణ:

ఇన్‌పుట్ బాక్స్ ఖాళీ ఉంటే (str.length==0), ఫంక్షన్ సూపర్ హింట్() ట్యాగ్ ట్రైల్ కంటెంట్ ను శుభ్రం చేసి ఫంక్షన్ ను నిష్క్రమిస్తుంది.

ఇన్‌పుట్ బాక్స్ ఖాళీ కానిది ఉంటే సూపర్ హింట్() ఈ దశలను అమలు చేస్తుంది:

  • XMLHttpRequest ఆబ్జెక్ట్ సృష్టించండి
  • సర్వర్ ప్రతిస్పందించినప్పుడు అది అమలు అవుతున్న ఫంక్షన్ సృష్టించండి
  • సర్వర్లోని ఫైల్కు అభ్యర్థన పంపండి
  • యూఆర్ఎల్ పైన జోడించబడిన పరామీటర్స్ (q) (ఇన్‌పుట్ బాక్స్ కంటెంట్ కలిగినది) ని గమనించండి

ఏస్ పి ఫైల్

ఈ జావాస్క్రిప్ట్ కాల్డ్ సర్వర్ పేజీ "gethint.asp" అనే ఏస్ పి ఫైల్.

"gethint.asp" 中的源代码会检查姓名数组,然后向浏览器返回对应的姓名:

<%
response.expires=-1
dim a(30)
'Fill up array with names
a(1)="Anna"
a(2)="Brittany"
a(3)="Cinderella"
a(4)="Diana"
a(5)="Eva"
a(6)="Fiona"
a(7)="Gunda"
a(8)="Hege"
a(9)="Inga"
a(10)="Johanna"
a(11)="Kitty"
a(12)="Linda"
a(13)="Nina"
a(14)="Ophelia"
a(15)="Petunia"
a(16)="Amanda"
a(17)="Raquel"
a(18)="Cindy"
a(19)="Doris"
a(20)="Eve"
a(21)="Evita"
a(22)="Sunniva"
a(23)="Tove"
a(24)="Unni"
a(25)="Violet"
a(26)="Liza"
a(27)="Elizabeth"
a(28)="Ellen"
a(29)="Wenche"
a(30)="Vicky"
'从 URL 获得参数 q
q=ucase(request.querystring("q"))
'如果长度 q>0,则从数组中查找所有提示
if len(q)>0 then
  hint=""
  for i=1 to 30
    if q=ucase(mid(a(i),1,len(q))) then
      if hint="" then
        hint=a(i)
      else
        hint=hint & " , " & a(i)
      end if
    end if
  next
end if
'హింట్ కనుగొనబడలేకపోతే, "no suggestion" అవుట్‌పుట్ చేయండి
'లేకపోతే సరైన విలువలను అవుట్‌పుట్ చేయండి
if hint="" then
  response.write("no suggestion")
else
  response.write(hint)
end if
%>

సోర్స్ కోడ్ వివరణ:

జావాస్క్రిప్ట్ ఏదైనా టెక్స్ట్ పంపింది ఉంటే (అంటే strlen($q) కంటే 0 మించినది ఉంటే), ఇది జరుగుతుంది:

  • 查找匹配来自 JavaScript 的字符的姓名
  • 如果未找到匹配,则将响应字符串设置为 "no suggestion"
  • 如果找到一个或多个匹配姓名,则用所有姓名设置响应字符串
  • 把响应发送到占位符 "txtHint"