<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 閱讀(1953) 評(píng)論(3)  編輯  收藏 所屬分類: ajax
    ??????今天又研究了一下autocomplete,終于又有一些些進(jìn)步了。終于動(dòng)態(tài)地調(diào)用遠(yuǎn)程的文件來(lái)改變選擇欄的內(nèi)容....返回來(lái)的格式是Flat-file Data ,,,不知道怎么翻譯好。大概就是文本格式..其實(shí)返回來(lái)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ù)
    (
    ???需要說(shuō)明的是輸入框要用這種格式
    ????????????<div?id="ysearchautocomplete0">
    ????????????????
    <input?id="ysearchinput0">
    ????????????????
    <div?id="ysearchcontainer0"></div>
    ????????????
    </div>
    其中ysearchcontainer0就是用來(lái)放下拉選擇的數(shù)據(jù)
    而發(fā)送的請(qǐng)求,yui都會(huì)自做主張的加上一個(gè)?query='+ysearchinput的值
    )

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

    接著就寫(xiě)下以下兩行代碼
    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)求,可能過(guò)大的消耗服務(wù)器資源.

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

    Feedback

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

    2007-11-03 01:11 by daiqiaobin
    我正要用yui做開(kāi)發(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ù)必清空頁(yè)面緩存
    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)問(wèn)樓主是怎么回事?。?/div>

    # 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

    主站蜘蛛池模板: 国产免费福利体检区久久| 亚洲一区二区三区首页 | 亚洲欭美日韩颜射在线二| 亚洲精品亚洲人成在线| 最新中文字幕免费视频| 亚洲卡一卡二卡乱码新区| 麻豆最新国产剧情AV原创免费 | 黄色a级免费网站| 免费在线观看理论片| 国产99久久亚洲综合精品 | 中文字幕精品亚洲无线码二区 | 成人免费视频一区| 亚洲日韩乱码中文字幕| 国产免费一区二区三区VR| 一级毛片试看60分钟免费播放| 亚洲色一色噜一噜噜噜| 中国国产高清免费av片| 婷婷精品国产亚洲AV麻豆不片| 最近中文字幕2019高清免费| 亚洲三级视频在线| 四虎亚洲国产成人久久精品| 中国一级毛片免费看视频| 亚洲视频在线一区二区三区| 无码国产精品一区二区免费I6| 亚洲国产精品精华液| 国产精品亚洲不卡一区二区三区 | 两性刺激生活片免费视频| 国产亚洲精品成人AA片| 无码欧精品亚洲日韩一区夜夜嗨| 中国内地毛片免费高清| 亚洲六月丁香婷婷综合| 亚洲国产成人久久综合野外| 性无码免费一区二区三区在线| 亚洲人成伊人成综合网久久| 又色又污又黄无遮挡的免费视| 最近中文字幕免费大全| 亚洲中文无码线在线观看| 高清在线亚洲精品国产二区| 久艹视频在线免费观看| 亚洲乱妇老熟女爽到高潮的片 | 国产免费高清69式视频在线观看|