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

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

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

    yui --------autocomplete學習二

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

    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" 這里是要調用的服務端請求.第二個參數就是要分隔的行數
    (
    ???需要說明的是輸入框要用這種格式
    ????????????<div?id="ysearchautocomplete0">
    ????????????????
    <input?id="ysearchinput0">
    ????????????????
    <div?id="ysearchcontainer0"></div>
    ????????????
    </div>
    其中ysearchcontainer0就是用來放下拉選擇的數據
    而發送的請求,yui都會自做主張的加上一個?query='+ysearchinput的值
    )

    看看和上一篇的oACDS定義來說.這是一種new YAHOO.widget.DS_XHR
    因為這是需要遠程調用所以需要用到connection.js這個js文件,所以一定要把它加進來
    粗略看過YAHOO.widget.DS_XHR這個類,它還是需要處理服務器返回來的數據,所以要定義responseType的屬性值。。其它兩個屬性設置可有可無

    接著就寫下以下兩行代碼
    oAutoComp2?=?new?YAHOO.widget.AutoComplete('ysearchinput2','ysearchcontainer2',?oACDS);???
    50?oAutoComp2.delimChar?=?";";???
    51?oAutoComp2.queryDelay?=?0;???
    52?oAutoComp2.prehighlightClassName?=?"yui-ac-prehighlight";??
    queryDelya屬性就是每隔幾秒發送一次請求..因為需要向服務器發生請求,可能過大的消耗服務器資源.

    需要說明的因為ajax都是以utf-8的方式進行處理數據的。所以返回的數據如果utf-8編碼的話當然就沒有問題啦。。但如果是其它的編碼的話.?
    就要在html響應中加上編碼格式charset="gb2312",php寫法是
    header("charset=gb2312")

    Feedback

    # re: yui --------autocomplete學習二  回復  更多評論   

    2007-11-03 01:11 by daiqiaobin
    我正要用yui做開發
    服務器端:

    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);
    //務必清空頁面緩存
    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測試文件</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學習二  回復  更多評論   

    2007-11-03 01:14 by daiqiaobin
    以上代碼報錯:
    this.connMgr 為空或不是對象
    請問樓主是怎么回事啊?

    # re: yui --------autocomplete學習二  回復  更多評論   

    2008-08-05 13:59 by raul86
    我現在在用這個東西,但是不知道調到Action之后如何返回數據。
    能不能給我一份動態查詢的例子,郵箱是raul_1986@126.com.

    只有注冊用戶登錄后才能發表評論。


    網站導航:
    博客園   IT新聞   Chat2DB   C++博客   博問  
     

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

    Copyright © yoyo

    主站蜘蛛池模板: 久久久久久av无码免费看大片| 成人网站免费看黄A站视频| 国产美女精品久久久久久久免费| 亚洲第一成年男人的天堂| 永久免费av无码入口国语片| 久久精品国产亚洲5555| 免费中文字幕视频| 亚洲国产成人精品久久久国产成人一区二区三区综 | 亚洲AV无码成人精品区狼人影院 | 91精品全国免费观看青青| 亚洲国产另类久久久精品黑人| 免费91最新地址永久入口| 亚洲成a人片在线观看中文!!! | 亚洲男人的天堂一区二区| 每天更新的免费av片在线观看 | 人人爽人人爽人人片A免费| 精品无码一区二区三区亚洲桃色 | 巨胸狂喷奶水视频www网站免费| 精品亚洲成在人线AV无码| 中文字幕亚洲专区| 成人超污免费网站在线看| 暖暖在线视频免费视频| 国产偷国产偷亚洲高清人 | 国产午夜免费高清久久影院| 亚洲一区二区三区成人网站| 亚洲第一AAAAA片| 国产一区二区视频免费| 日韩精品福利片午夜免费观着| 你懂的在线免费观看| 黄色a三级免费看| 亚洲欧美综合精品成人导航| 亚洲国产精久久久久久久| 亚洲精品线路一在线观看| 精品久久洲久久久久护士免费| 91精品手机国产免费| 中文字幕无线码中文字幕免费| 风间由美在线亚洲一区| 亚洲 暴爽 AV人人爽日日碰| 麻豆亚洲av熟女国产一区二| 亚洲精品无码成人片久久| 亚洲国产精品一区二区第四页 |