Recommended: Perceive the power of ASP through startup scripts Like most language scripts, the best way to learn ASP is to try ASP yourself and install PWS or IIS using your own system. You can test ASP components and functions on your own server while learning. To facilitate learning, we have compiled some fucks
The main documents are:
Index.html implements functions, a text box, enters content and implements prompts
Search.asp query function, let the content entered in the text box be queried in the database, and then returned to the client
The conn.asp database connection function realizes the xmlhttp.js AJAX core part, which is used to pass the client's data to the server and then return the server's data to the client.
style.css style file, mainly styles the content queryed by Google prompt box, mainly styling the contents found in Google
First look at the first file style.css
| The following is the quoted content: [code=css] @charset utf-8; /* CSS Document */ Body { font-size:12px; font-family:Arial, Helvetica, sans-serif; } #search_suggest { position:absolute; background:#FFFFFF; text-align:left; border:1px #000000 solid; } .suggest_link_over { background-color:#e8f2fe; padding:2px 6px; } .suggest_link { padding:2px 6px; background-color:#FFFFF; } .none { display:none; } |
The second file: xmlhttp.js
| The following is the quoted content: // JavaScript Documentrt var xmlHttp = createXmlHttpRequest(); function createXmlHttpRequest() { var xmlhttp = null; try { xmlhttp = XMLHttpRequest(); } catch(e1) { try { xmlhttp = new ActiveXObject(MSXML2.XMLHTTP); } catch(e2) { try { xmlhttp = new ActiveXObject(Microsoft.XMLHTTP); } catch(e3) { xmlhttp = false; alert(creation failed!); } } } return xmlhttp; } function change_key() { if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0) { var str = document.getElementById(txt_key).value; xmlHttp.open(get,search.asp?key= str,true); xmlHttp.onreadystatechange = handSearchRequest; xmlHttp.send(null); } } function handSearchRequest() { if (xmlHttp.readyState == 4) { var div = document.getElementById(search_suggest); div.innerHTML = ; var str = xmlHttp.responseText.split(|); for (var i=0; i<str.length; i ) { var suggest = '<div onmouseover=javascript: suggestOver(this); '; suggest = 'onmouseout=javascript: suggestOut(this); '; suggest = 'onclick=javascript:setSearch(this.innerHTML); '; suggest = 'class=suggest_link> ' str[i] '</div> '; div.innerHTML = suggest; } } } function setSearch(div_value) { document.getElementById(txt_key).value = div_value; document.getElementById(search_suggest).className = 'none '; } function suggestOver(div_value) { div_value.className = 'suggest_link_over '; } function suggestOut(div_value) { div_value.className = 'suggest_link '; } |
The third file: conn.asp
| The following is the quoted content: <% set conn = Server.CreateObject(Adodb.Connection) connStr = Provider=SQLOLEDB;Server=./SQLEXPRESS;UID=sa;PWD=sa;Initial catalog=test; conn.ConnectionString = connStr conn.open %> |
The fourth file: search.asp
| The following is the quoted content: <%@LANGUAGE=VBSCRIPT CODEPAGE=65001%> <!-- #include file=conn.asp --> <% key = request.QueryString(key) if (key <> ) then key = replace(key,/,) key = replace(key, ',) key = replace(key,or,) sel_sql = select [key] from [key] where [key] like ' & key & % ' dim keyword keyword = set rs = conn.execute (sel_sql) do while not rs.eof keyword = keyword & rs(0) & | rs.movenext loop response.Write(keyword) end if %> |
The last result file: index.html
| The following is the quoted content: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd> <html xmlns=http://www.w3.org/1999/xhtml> <head> <meta http-equiv=Content-Type content=text/html; charset=utf-8 /> <title>google prompt</title> <script src=xmlhttp.js >/script> <link rel=stylesheet type=text/css href=style.css> </head> <body> <form id=form1 name=form1 method=post action=> <input name=txt_key type=text id=textarea autocomplete=off onkeyup=change_key()/><br/> <div id=search_suggest ></div> </form> </body> </html> |
Share: A brief discussion on 19 basic tips for ASP dynamic web programming 1. The current date and time command is %=now%> 2. The method of ASP to obtain table data input is to use a built-in object-Request, which varies from get and post. 3. If you want to write it yourself in VB or other language