javascript - 如何在远程函数中传递两个值?

标签 javascript php jquery

我想将多个值传递到 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调用您可以看到

http://suggestqueries.google.com/complete/search?client=chrome&q=%QUERY&newField=10&callback=jQuery191022225840536777897_1447822862109&_=1447822862110

其中“newField”是另一个输入字段

Here The Working Fiddle

关于javascript - 如何在远程函数中传递两个值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33757398/

相关文章:

javascript - 代码在 Fiddle 上运行但不在网站上运行

javascript - jQuery,下一个,上一个,循环到第一个和最后一个

javascript - Socket.io.js - 授权时拒绝连接后仍然建立连接

php - 使用哪个tinyMCE包?

javascript - JQuery 幻灯片故障

javascript - Facebook Pixel + Google 标签管理器 + fbq 事件

php - 编辑nmap2db.pl(更改数据库更新语句)

php - 在月初和月末获取一周的开始日期和结束日期

javascript - 相当于 jQuery .is() 的 JS

javascript - jQuery .wrapAll() 重置嵌套元素的滚动