开发者

YUI drive me crazy

开发者 https://www.devze.com 2023-03-09 12:36 出处:网络
I copy this code in my page with same ids name and all and its never work <!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">

I copy this code in my page with same ids name and all and its never work

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="pasha_js/yui-min.js"></script>
<script type="text/javascript">
YAHOO.example.Data.arrayStates = [ 
        "Alabama", 
        "Alaska", 
        "Arizona", 
        "Arkansas", 
        "California", 
        "Colorado", 
        "Connecticut", 
        "Delaware", 
        "Florida", 
        ... 
    ]; 
    YAHOO.example.BasicRemote = function() { 
            // Use an XHRDataSource 
            var oDS = new YAHOO.util.XHRDataSource("assets/php/ysearch_flat.php"); 
            // 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>
<style type="text/css">
 #myAutoComplete 
 { 
        width:15em; /* set width here or else widget will expand to fit its container */ 
        padding-bottom:2em; 
    } 
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<label for="myInput">Search our database:</label> 
    <div id="myAutoComplete"> 
        <input id="myInput" type="text"> 
        <div id="myContainer"></div> 
    </div> 
</body>
</html>

any ideas why?


look at this line

var oDS = new YAHOO.util.XHRDataSource("assets/php/ysearch_flat.php")

do you have a php file on your server at that location that will return data in a format that AutoComplete will understand? If you open up your developer tools you should see a bunch of 404 XHR requests to that file, which is why you never get any results.

0

精彩评论

暂无评论...
验证码 换一张
取 消