jQueryAutoCompleteではデフォルトの送信パラメタはtermのみでちょっと使い勝手が悪かったりします。
そこでカスタマイズしてみます
source:function(request,response)をオーバーライド
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <html> <head> <title>Insert title here</title> <meta content="text/html; charset=UTF-8" http-equiv="content-type" /> <script type="text/javascript" src="./jquery-1.9.0.js"> </script> <script type="text/javascript" src="./jquery-ui.js"> </script> <script type="text/javascript" src="./test.js"></script> <link rel="stylesheet" type="text/css" href="./jquery-ui.css"> </head> <body> <div class="ui-widget"> <input type="hidden" name="val1" id="val1" value="1234567890" /> <input type="hidden" name="val2" id="val2" value="aaaaa" /> <input id="searchTags" /> </div> </body> </html> |
test.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | $(function() { var url="./searchEngine.jsp"; var val1=$("#val1").val(); var val2=$("#val2").val(); $( "#searchTags" ).autocomplete({ source : function( request, response ) { request["val1"]=val1; request["val2"]=val2; $.ajax({ url: url, data: request, dataType: "jsonp", jsonpCallback:'callback', success: function( data ) { response( data ); }, error: function() { response( [] ); } }); }, }); }); |
searchEngine.jsp
1 2 3 4 5 6 7 8 9 10 11 | <%@ page language="java" contentType="text/html; charset=Shift_JIS" pageEncoding="Shift_JIS"%> Map map = request.getParameterMap(); Iterator it = map.keySet().iterator(); while (it.hasNext()) { String name = (String)it.next(); String[] val = (String[])map.get(name); for (int i = 0;i<val.length;i++) { System.out.println(name + "=" + val[i] ); } } |