Prompt data is displayed below the search box (data is AJAX read)

Source: Internet
Author: User

1. Front Page

1<div style="margin:0 Auto">2<input type="text"Id="Wenxiantxt"onkeyup="clickevent ()"style="width:250px; height:25px"/>3<ul id=" All"style="Width:250px;height:auto; margin-top:0px;">4</ul>5</div>

2. Backstage Code

1 [WebMethod]2          Public Static stringGetjson (stringURLs)3         {4HttpWebRequest request =(HttpWebRequest) webrequest.create (URLs);5Request. Method ="GET";6Request. ContentType ="Application/json; Charset=utf-8";7HttpWebResponse response =(HttpWebResponse) request. GetResponse ();8Stream Myresponsestream =Response. GetResponseStream ();9StreamReader Mystreamreader =NewStreamReader (Myresponsestream, Encoding.UTF8);Ten             stringRetString =mystreamreader.readtoend (); One mystreamreader.close (); A myresponsestream.close (); -  -             returnretstring; the  -}

3. jquery

<style type="Text/css">ul li {list-Style:none; Font-size:12px; Text-Decoration:none;            Color:gray;            Cursor:pointer;            padding:0px; Margin-left:-35px; }  </style> <script type="Text/javascript">function clickevent () {URLs="HTTP://WWW.SUGGEST?&Q=HIV&SRC=CN"; $.ajax ({type:"Post",                Async:false, URL:"2_sousuotishi.aspx/getjson", ContentType:"Application/json; Charset=utf-8", Data:"{urls: '"+ URLs +"'}", DataType:"JSON", Success:function (data) {varJsondata = eval ("("+ DATA.D +")"); $("#all"). empty (); //Debugger;                     for(vari =0; I < jsondata['Data'].length; i++) {                        varHTML2 =""; HTML2+="<li>"+ jsondata['Data'][i] +"</li>"; $("#all"). Append (HTML2); }                    //Select the text of the search hint to the search box$("Li"). On ("Click", Function () {$ ("#wenxiantxt"). Val ($ ( This). text ()); $("#all"). HTML ("");                    }); $("Li"). MouseMove (function () {$ ("Li"). CSS ("Background-color",""); $( This). CSS ("Background-color","Gray"); $("Li"). CSS ("Color","Gray"); $( This). CSS ("Color"," White");                }); }, Error:function (err) {alert ("error! ");        }            }); }    </script>

4. Display style

Select one to text box

Prompt data is displayed below the search box (data is AJAX read)

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.