Ajax implementation class Google suggest Effect

Source: Internet
Author: User

Ajax implementation class Google suggest Effect

* Project name: Ajax implementation class Google suggest Effect
* Author: Crawler
* Contact: caolvchong@gmail.com
* Time: 2007-7-7
* Cause:
This problem was raised during the internship interview. It took a lot of time to come back and try it out. it is mainly about the performance of JavaScript on the front-end, database structure design, and so on. there are a few Dom tutorials on the Internet, but there is no reference, and <conquer Ajax Web2.0 development technology details> in chapter 16th search tips (suggest) the example in is really simple (of course JavaScript), and the database uses MSSQL and the background language uses JSP, which is out of harmony with the familiar ones (though they will be used later ), so I did it myself. imitation effect: Google suggest
* Development Platform: Windows2003 iis6.0 Access Database
* Tools: Dreamweaver (write ASP), Aptana (write JavaScript, HTML and CSS), emeditor (write this article), access2003 (database)
* Test Platform: firefox2.0, ie6.0, and ie7.0
* Demo address: http://finish.3322.org/suggest/index.htm (short term valid, on the local machine, possible access not smooth)
* Address: http://cceer.xmu.edu.cn/blog/view.asp? Id = 55 (please note)
*: File structure:
Index.htm: homepage, display results
Ajax_result.asp: Ajax call background return result File
Result. asp: the search result file, which I did not do. The specific functions are written as needed.
Database (suggest. mdb ):
ID: Automatic ID
Keyword: keyword
Seachtimes: Number of times searched
Matchnum. so it must be added to other database tables in the background at some time. I originally wanted to do this, but it was limited to the immature algorithm and time constraints. so we use a random number to replace it .)
* Problems encountered during development:
1. CSS: encountered the IE Double Floating boundary bug (float: the margin-left under left is twice the setting, and is eliminated using display: inline)
2. javascript:
One is that the question of the global variable J's upper and lower boundaries really upset me for a while, but it's better to clear up the train of thought.
Key event compatibility: IE keycode and which events of other browsers
The difference between onkeypress and onkeyup and onkeydown events: onkeypress only accepts numbers and letters, and does not accept system buttons (such as up and down
Direction keys)
When the submit () method is used, the ID or name of a tag cannot be defined as submit. Otherwise, an object is missing.
There are still some details to judge the problem, and I have paid a lot of attention.
3.html:
How to make the form invisible (in Firefox, automatic memory will block the main Ajax part, but Google does not have such a prompt function, so the form memory function is removed ), you only need to add AutoComplete = "off" to the form"
* Supplement:
There are still some gaps with Google suggest, such as the issue of always following the direction keys and other details, which need to be improved.
*:

Limited by the length of the article, only post the homepage and JS, and download other attachments:
Crawler -- suggest.rar
Home: index.htm


<! Doctype HTML public "-// W3C // dtd xhtml 1.0 strict // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml" lang = "gb2312">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> crawler --- simple Google suggest </title>
<Link type = "text/CSS" rel = "stylesheet" href = "suggest.css"/>
<SCRIPT type = "text/JavaScript" src = "suggest. js"> </SCRIPT>
</Head>
<Body onclick = "hide_suggest ();">

<Form action = "result. asp" method = "Post" name = "Search" AutoComplete = "off">
<! -- Input type = "text" name = "keyword" id = "keyword" onkeyup = "keydeal (event);" onclick = "keydeal (event);"/-->
<Input type = "text" name = "keyword" id = "keyword" onkeyup = "keyupdeal (event);" onkeydown = "keydowndeal (event ); "onclick =" keyupdeal (event); "/>
<Input type = "Submit" value = "good luck"/>
<Div id = "suggest"> </div>
</Form>
</Body>
</Html>

Suggest. js

var j=-1;var temp_str;var $=function(node){return document.getElementById(node);}var $$=function(node){return document.getElementsByTagName(node);}function ajax_keyword(){var xmlhttp;try{xmlhttp=new XMLHttpRequest();}catch(e){xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}xmlhttp.onreadystatechange=function(){if (xmlhttp.readyState==4){if (xmlhttp.status==200){var data=xmlhttp.responseText;$("suggest").innerHTML=data;j=-1;}}}xmlhttp.open("post", "ajax_result.asp", true);xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');xmlhttp.send("keyword="+escape($("keyword").value));}function keyupdeal(e){var keyc;if(window.event){keyc=e.keyCode;}else if(e.which){keyc=e.which;}if(keyc!=40 && keyc!=38){ajax_keyword();temp_str=$("keyword").value;}}function set_style(num){for(var i=0;i<$$("li").length;i++){var li_node=$$("li")[i];li_node.className="";}if(j>=0 && j<$$("li").length){var i_node=$$("li")[j];$$("li")[j].className="select";}}function mo(nodevalue){j=nodevalue;set_style(j);}function form_submit(){if(j>=0 && j<$$("li").length){$$("input")[0].value=$$("li")[j].childNodes[0].nodeValue;}document.search.submit();}function hide_suggest(){var nodes=document.body.childNodesfor(var i=0;i
 
  <$$("li").length){j++;if(j>=$$("li").length){j=-1;}}if(j>=$$("li").length){j=-1;}}if(keyc==38){if(j>=0){j--;if(j<=-1){j=$$("li").length;}}else{j=$$("li").length-1;}}set_style(j);if(j>=0 && j<$$("li").length){$("keyword").value=$$("li")[j].childNodes[0].nodeValue;}else{$("keyword").value=temp_str;}}}
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.