ఏజాక్స్ ASP ఎక్సామ్ప్లే
- ముందు పేజీ AJAX PHP
- తరువాత పేజీ AJAX డేటాబేస్
AJAX సమాంతర ప్రపంచంలో అనుకూలమైన అనువర్తనాలను సృష్టించడానికి ఉపయోగిస్తారు.
ఏజాక్స్ ASP ఎక్సామ్ప్లే
ఈ ఉదాహరణలో, వినియోగదారుడు ఇన్పుట్ ఫీల్డ్లో అక్షరాలను తప్పించినప్పుడు, వెబ్ సర్వర్తో వెబ్ పేజీ కమ్యూనికేషన్ ఎలా జరుగుతుంది చూడండి:
ప్రామాణికం
దయచేసి ఈ ఇన్పుట్ ఫీల్డ్లో అక్షరాలు A-Z లో తప్పక నమోదు చేయండి:
పేరు:
శోధన సలహాలు:
ఉదాహరణ వివరణ
ఈ ఉదాహరణలో, వినియోగదారుడు ఇన్పుట్ ఫీల్డ్లో అక్షరాలను తప్పించినప్పుడు, "showHint()" అనే ఫంక్షన్ అమలు అవుతుంది.
ఈ ఫంక్షన్ onkeyup ఇవెంట్ అనుసరించబడుతుంది.
ఈ క్రింది మూల కోడ్:
ప్రామాణికం
<html> <head> <script> function showHint(str) { if (str.length == 0) { document.getElementById("txtHint").innerHTML = ""; return; } else { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("txtHint").innerHTML = this.responseText; } }; xmlhttp.open("GET", "gethint.asp?q=" + str, true); xmlhttp.send(); } } </script> </head> <body> <p><b>క్రింది ఇన్పుట్ ఫీల్డ్ లో A-Z అక్షరాలను అంకితం చేయండి:</b></p> <form> పేరు:<input type="text" onkeyup="showHint(this.value)"> </form> <p>శోధన సలహాలు:<span id="txtHint"></span></p> </body> </html>
కోడ్ వివరణలు:
మొదటగా, ఇన్పుట్ ఫీల్డ్ ఖాళీ కాదా తనిఖీ చేయండి (str.length == 0
);అయితే, ఉంటే txtHint ప్లేస్ హోల్డర్ సమాచారాన్ని శుభ్రం చేసి ఫంక్షన్ ను బయటపడండి。
కానీ, ఇన్పుట్ ఫీల్డ్ ఖాళీ కాది అయితే ఈ పద్ధతిని అనుసరించండి:
- XMLHttpRequest ఆబ్జెక్ట్ సృష్టించండి
- సర్వర్ ప్రతిస్పందించినప్పుడు అమలు అవుతుంది ఫంక్షన్ సృష్టించండి
- సర్వర్ పైని ASP ఫైలుకు (gethint.asp) అభ్యర్ధనను పంపండి
- దయచేసి gethint.asp కు q పరామితిని జోడించండి
- str వ్యవస్థాపకం ఇన్పుట్ ఫీల్డ్ యొక్క సమాచారాన్ని కాపాడుతుంది
ASP ఫైలు - "gethint.asp"
ఈ ASP ఫైలు పేరు సమూహాన్ని తనిఖీ చేసి బ్రౌజర్ కు సంబంధించిన పేరు అందిస్తుంది:
<% response.expires=-1 dim a(32) పేరు ను సమూహానికి చేర్చండి a(1)="Ava" a(2)="Brielle" a(3)="Caroline" a(4)="Diana" a(5)="Elise" a(6)="Fiona" a(7)="Grace" a(8)="Hannah" a(9)="Ileana" a(10)="Jane" a(11)="Kathryn" a(12)="Laura" a(13)="Millie" a(14)="Nancy" a(15)="Opal" a(16)="Petty" a(17)="Queenie" a(18)="Rose" a(19)="Shirley" a(20)="Tiffany" a(21)="Ursula" a(22)="Victoria" a(23)="Wendy" a(24)="Xenia" a(25)="Yvette" a(26)="Zoe" a(27)="Angell" a(28)="Adele" a(29)="Beatty" a(30)="Carlton" a(31)="Elisabeth" a(32)="Violet" 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 %>
- ముందు పేజీ AJAX PHP
- తరువాత పేజీ AJAX డేటాబేస్