<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    yui --------autocomplete學(xué)習(xí)二

    Posted on 2007-05-24 02:20 yoyo 閱讀(1949) 評(píng)論(3)  編輯  收藏 所屬分類: ajax
    ??????今天又研究了一下autocomplete,終于又有一些些進(jìn)步了。終于動(dòng)態(tài)地調(diào)用遠(yuǎn)程的文件來改變選擇欄的內(nèi)容....返回來的格式是Flat-file Data ,,,不知道怎么翻譯好。大概就是文本格式..其實(shí)返回來xml,json格式會(huì)更好處理。

    1oACDS?=?new?YAHOO.widget.DS_XHR("./php/ysearch_flat.php",?["\n",?"\t"]);???
    2?oACDS.responseType?=?YAHOO.widget.DS_XHR.TYPE_FLAT;???
    3?oACDS.maxCacheEntries?=?60;???
    4?oACDS.queryMatchSubset?=?true;???
    5



    "./php/ysearch_flat.php" 這里是要調(diào)用的服務(wù)端請(qǐng)求.第二個(gè)參數(shù)就是要分隔的行數(shù)
    (
    ???需要說明的是輸入框要用這種格式
    ????????????<div?id="ysearchautocomplete0">
    ????????????????
    <input?id="ysearchinput0">
    ????????????????
    <div?id="ysearchcontainer0"></div>
    ????????????
    </div>
    其中ysearchcontainer0就是用來放下拉選擇的數(shù)據(jù)
    而發(fā)送的請(qǐng)求,yui都會(huì)自做主張的加上一個(gè)?query='+ysearchinput的值
    )

    看看和上一篇的oACDS定義來說.這是一種new YAHOO.widget.DS_XHR
    因?yàn)檫@是需要遠(yuǎn)程調(diào)用所以需要用到connection.js這個(gè)js文件,所以一定要把它加進(jìn)來
    粗略看過YAHOO.widget.DS_XHR這個(gè)類,它還是需要處理服務(wù)器返回來的數(shù)據(jù),所以要定義responseType的屬性值。。其它兩個(gè)屬性設(shè)置可有可無

    接著就寫下以下兩行代碼
    oAutoComp2?=?new?YAHOO.widget.AutoComplete('ysearchinput2','ysearchcontainer2',?oACDS);???
    50?oAutoComp2.delimChar?=?";";???
    51?oAutoComp2.queryDelay?=?0;???
    52?oAutoComp2.prehighlightClassName?=?"yui-ac-prehighlight";??
    queryDelya屬性就是每隔幾秒發(fā)送一次請(qǐng)求..因?yàn)樾枰蚍?wù)器發(fā)生請(qǐng)求,可能過大的消耗服務(wù)器資源.

    需要說明的因?yàn)閍jax都是以u(píng)tf-8的方式進(jìn)行處理數(shù)據(jù)的。所以返回的數(shù)據(jù)如果utf-8編碼的話當(dāng)然就沒有問題啦。。但如果是其它的編碼的話.?
    就要在html響應(yīng)中加上編碼格式charset="gb2312",php寫法是
    header("charset=gb2312")

    Feedback

    # re: yui --------autocomplete學(xué)習(xí)二  回復(fù)  更多評(píng)論   

    2007-11-03 01:11 by daiqiaobin
    我正要用yui做開發(fā)
    服務(wù)器端:

    AutoComp.java-------------------------------

    package ajaxdemo1;

    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;

    public class AutoComp extends HttpServlet {
    private static final String CONTENT_TYPE = "text/xml; charset=UTF-8";

    //Initialize global variables
    public void init() throws ServletException {
    }

    //Process the HTTP Get request
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws
    ServletException, IOException {
    response.setContentType(CONTENT_TYPE);
    //務(wù)必清空頁面緩存
    response.addHeader("Cache-Control","no-cache");

    System.out.println("url = " + request.getRequestURL() + "?" + request.getQueryString());
    String query = request.getParameter("query");

    PrintWriter out = response.getWriter();
    out.print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    out.print("<Resultset>");
    for(int i=0;i<40;i++){
    out.print("<Result>");
    out.print("<Title>title"+i+"</Title>");
    out.print("<Summary>Hello World"+i+"!</Summary>");
    out.print("</Result>");
    }
    out.print("</Resultset>");
    out.close();
    }

    //Process the HTTP Post request
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws
    ServletException, IOException {
    doGet(request, response);
    }

    //Clean up resources
    public void destroy() {
    }
    }

    index.jsp================================

    <%@ page contentType="text/html; charset=GBK" %>
    <!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>
    <title>AJAX測(cè)試文件</title>

    <link rel="stylesheet" type="text/css" href="build/fonts/fonts-min.css" />
    <link rel="stylesheet" type="text/css" href="build/autocomplete/assets/skins/sam/autocomplete.css" />
    <script type="text/javascript" src="build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="build/animation/animation.js"></script>
    <script type="text/javascript" src="build/autocomplete/autocomplete.js"></script>
    <script type="text/javascript" src="build/yahoo/yahoo.js"></script>
    <script type="text/javascript" src="build/event/event.js"></script>
    <script type="text/javascript" src="build/connection/connection.js"></script>

    <!--begin custom header content for this example-->
    <style type="text/css">
    /* custom styles for this example */
    #ysearchautocomplete{
    margin-bottom:2em;
    width:25em;
    }
    </style>

    </head>
    <body class="yui-skin-sam">

    <form action="http://localhost:8080/ajax" onsubmit="return YAHOO.example.ACXml.validateForm();">
    <h3>Yahoo! Search:</h3>
    <div id="ysearchautocomplete">
    <input id="ysearchinput" type="text" name="p">
    <div id="ysearchcontainer"></div>
    </div>
    </form>

    <script type="text/javascript" >
    YAHOO.example.ACXml = new function(){

    // Instantiate an XHR DataSource and define schema as an array:
    // ["Multi-depth.object.notation.to.find.a.single.result.item",
    // "Query Key",
    // "Additional Param Name 1",
    // ...
    // "Additional Param Name n"]

    this.oACDS = new YAHOO.widget.DS_XHR("http://localhost:8080/ajax/autocomp", ["Result", "Title", "Summary"]);
    this.oACDS.responseType = YAHOO.widget.DS_XHR.TYPE_XML;
    //this.oACDS.queryMatchContains = true;
    //this.oACDS.scriptQueryAppend = ""; // Needed for YWS
    // Instantiate AutoComplete

    this.oAutoComp = new YAHOO.widget.AutoComplete("ysearchinput","ysearchcontainer", this.oACDS);

    // Display up to 20 results in the container
    this.oAutoComp.maxResultsDisplayed = 10;

    // Require user to type at least 1 characters before triggering a query
    this.oAutoComp.minQueryLength = 1;

    // Every key input event will trigger an immediate query...
    this.oAutoComp.queryDelay = 0;

    // ...or queries will be sent after 3 seconds have passed
    // since the last key input event
    //this.oAutoComp.queryDelay = 3;
    // Do not automatically highlight the first result item in the container
    this.oAutoComp.autoHighlight = false;

    // Enable a drop-shadow under the container element
    this.oAutoComp.useShadow = true;

    // Enable an iFrame shim under the container element
    this.oAutoComp.useIFrame = true;

    this.oAutoComp.formatResult = function(oResultItem, sQuery) {
    return oResultItem[0] + " " + oResultItem[1];
    };


    // Stub for AutoComplete form validation
    this.validateForm = function() {
    // Validation code goes here
    return true;

    };

    };
    </script>

    </body>
    </html>

    # re: yui --------autocomplete學(xué)習(xí)二  回復(fù)  更多評(píng)論   

    2007-11-03 01:14 by daiqiaobin
    以上代碼報(bào)錯(cuò):
    this.connMgr 為空或不是對(duì)象
    請(qǐng)問樓主是怎么回事啊?

    # re: yui --------autocomplete學(xué)習(xí)二  回復(fù)  更多評(píng)論   

    2008-08-05 13:59 by raul86
    我現(xiàn)在在用這個(gè)東西,但是不知道調(diào)到Action之后如何返回?cái)?shù)據(jù)。
    能不能給我一份動(dòng)態(tài)查詢的例子,郵箱是raul_1986@126.com.

    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     

    posts - 2, comments - 4, trackbacks - 0, articles - 4

    Copyright © yoyo

    主站蜘蛛池模板: 亚洲人成中文字幕在线观看| 九九综合VA免费看| 好看的亚洲黄色经典| 成人免费视频软件网站| 国产亚洲免费的视频看| 国产AV无码专区亚洲AV琪琪| 亚洲一区二区三区无码国产| 久久亚洲国产欧洲精品一| 可以免费观看一级毛片黄a| 曰批视频免费30分钟成人| a国产成人免费视频| 深夜a级毛片免费无码| 亚洲色偷偷偷综合网| 亚洲综合久久1区2区3区| 亚洲精品乱码久久久久久| 亚洲成a人片在线观看国产| 久久精品网站免费观看| 成人免费福利视频| 免费无遮挡无码永久视频| 中国性猛交xxxxx免费看| 一级毛片高清免费播放| 国产成人 亚洲欧洲| 亚洲乱色伦图片区小说| 久久精品国产亚洲AV久| 亚洲毛片基地日韩毛片基地| 亚洲精品线在线观看| 国产亚洲无线码一区二区| 在线日韩日本国产亚洲| 亚洲日产韩国一二三四区| 色噜噜亚洲精品中文字幕| 久久久久一级精品亚洲国产成人综合AV区| 国产婷婷高清在线观看免费 | 女人被男人桶得好爽免费视频| 曰批全过程免费视频播放网站| 久久99热精品免费观看动漫| a级日本高清免费看| 中文字幕久精品免费视频| 精品视频一区二区三区免费| 青柠影视在线观看免费高清| 免费视频精品一区二区三区 | 日韩中文字幕免费|