我想将多个值传递到 search.php
页面,我该如何做到这一点?
<html>
<head>
<title>Ajax Search Box using PHP and MySQL</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="typeahead.min.js"></script>
<script >
$(document).ready(function(){
$('input.typeahead').typeahead({
name: 'typeahead',
remote: 'search.php?key=%QUERY',
prefetch: 'search.php',
limit : 10
});
});
</script>
</style>
</head>
<body>
<h1>Ajax Search Box using Node and MySQL</h1>
<button type="button" >Visit Tutorial</button>
<input type="text" name="typeahead" class="typeahead" autocomplete="off" spellcheck="false" placeholder="Type your Query">
</body>
</html>
最佳答案
仅使用 & 不适用于 typeahead,您需要在设置之前使用 replace
来处理查询字符串。
$('#Last_Name').typeahead({
name: 'typeahead',
remote: {
url: 'Search.pl?query=%QUERY',
replace: function(url, uriEncodedQuery) {
var QUERY2 = $("#textfield").val(); // get other field value
if (!val) return url;
return url + '&Key2=' + encodeURIComponent(QUERY2)
},
limit : 10
});
编辑后:
我创建了一个带有两个输入框的 fiddle ,一个有预先输入,另一个输入的值只是通过类型头传递,您将通过网络面板(firebug)看到它,或者您是否使用查看ajax调用您可以看到
其中“newField”是另一个输入字段
关于javascript - 如何在远程函数中传递两个值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33757398/