我一直在尝试使用this issue code作为发布而不是默认的方式,而不会破坏typeahead的优点。除了我似乎无法弄明白,我挣扎到足以弄清楚这一点,但现在我没有线索。
有人能指出我正确的方向吗?我的代码注释掉了新代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Submit Deal test</title>
<!-- Bootstrap -->
<link href="css/bootstrap.css" rel="stylesheet">
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<!-- for twitter typeahead bundle -->
<script src="js/typeahead.bundle.js"></script>
</head>
<?php /*authenticate the user is going from submitdeal.php*/
session_start();
$_SESSION['token'] = 10;
?>
<script type='text/javascript'>//<![CDATA[
$(window).load(function(){
var brands;
brands = new Bloodhound({
datumTokenizer: function(d) { return Bloodhound.tokenizers.whitespace(d.num); },
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: 'brands.php?query=%QUERY'
/*url: 'brands.php'
// since we use POST, the URL never changes so we simulate a different URL for each query
// for the typeahead internal request cache.
replace: function (url, uriEncodedQuery){
return url + "#" + uriEncodedQuery; // the part after the hash is not sent to the server
},
beforeSend: function (jqXhr, settings){
jqXhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
settings.type = 'POST';
settings.hasContent = true;
settings.data = $.param({beneficiary: queryInput.val()});
},*/
}
});
brands.initialize();
$('.typeahead').typeahead(null, {
displayKey: 'name',
source: brands.ttAdapter()
});
});//]]>
</script>
</head>
<body>
<input class="typeahead" type="text" placeholder="begin typing the brand" autocomplete="off">
</body>
</html>