0 0

YUI的autocomplete功能调用ajax数据,不能自动完成了10

YUI的autocomplete功能调用ajax数据,不能自动完成了,比如我有adyerwer输入ad不定位到adyerwer
qq89062647
主页面:ac_basic_xhr_clean.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
	import="java.util.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>


    <meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Basic Remote Data</title>

<style type="text/css">
/*margin and padding on body element
  can introduce errors in determining
  element position and are not recommended;
  we turn them off as a foundation for YUI
  CSS treatments. */
body {
	margin:0;
	padding:0;
}
</style>

<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/connection/connection-min.js"></script>
<script type="text/javascript" src="../../build/animation/animation-min.js"></script>
<script type="text/javascript" src="../../build/datasource/datasource-min.js"></script>
<script type="text/javascript" src="../../build/autocomplete/autocomplete-min.js"></script>


<!--begin custom header content for this example-->
<style type="text/css">
#myAutoComplete {
    width:25em; /* set width here or else widget will expand to fit its container */
    padding-bottom:2em;
}
</style>


<!--end custom header content for this example-->

</head>

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


<h1>Basic Remote Data</h1>

<div class="exampleIntro">
	<p>This AutoComplete implementation points to an online script that serves a data as delimited plain text. Enabling caching on the DataSource can reduce trips to the server and speed performance for repeated queries.</p>
			
</div>

<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== -->

<label for="myInput">Search our database:</label>
<div id="myAutoComplete">
	<input id="myInput" type="text">
	<div id="myContainer"></div>
</div>

<script type="text/javascript">
YAHOO.example.BasicRemote = function() {
    // Use an XHRDataSource
    var oDS = new YAHOO.util.XHRDataSource("handle.jsp");
    // Set the responseType
    oDS.responseType = YAHOO.util.XHRDataSource.TYPE_TEXT;
    // Define the schema of the delimited results
    oDS.responseSchema = {
        recordDelim: "\n",
        fieldDelim: "\t"
    };
    // Enable caching
    oDS.maxCacheEntries = 5;

    // Instantiate the AutoComplete
    var oAC = new YAHOO.widget.AutoComplete("myInput", "myContainer", oDS);
    
    return {
        oDS: oDS,
        oAC: oAC
    };
}();
</script>

<!--END SOURCE CODE FOR EXAMPLE =============================== -->

</body>
</html>



AJAX处理页面:handle.jsp

<%@ page language="java" contentType="text/xml; charset=UTF-8"
	import="java.util.*,java.io.*"%>
	
<%
response.setHeader("Cache-Control", "no-cache");

StringBuffer sb=new StringBuffer("");

 sb.append("adoiewewe\nadyerwer\nadlarewr\teeeee");


PrintWriter outPW=response.getWriter();
System.out.print("te"+sb.toString());
outPW.write(sb.toString());
outPW.close();
%>


YUI 
2010年5月03日 22:21
目前还没有答案

相关推荐

Global site tag (gtag.js) - Google Analytics