Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何进行自动建议,哪些应该来自数据库,一旦选择,它应该自动填充文本框?_Javascript_Jquery_Mysql_Jsp_Autocomplete - Fatal编程技术网

Javascript 如何进行自动建议,哪些应该来自数据库,一旦选择,它应该自动填充文本框?

Javascript 如何进行自动建议,哪些应该来自数据库,一旦选择,它应该自动填充文本框?,javascript,jquery,mysql,jsp,autocomplete,Javascript,Jquery,Mysql,Jsp,Autocomplete,Suggestion文本框,其中的数据应来自数据库,一旦选中,应自动从数据库填充。如何在Jquery中使用自动完成。这是我的密码 Index.jsp ` 函数myFun(){ //$.getJSON(“list.jsp”,{q:$(“#country”).val()},displayResult); $.ajax({type:“POST”,url:“list.jsp”, 数据:“q=“+document.getElementById(“国家”)。值, 成功:函数(数据){$(“#txthint

Suggestion文本框,其中的数据应来自数据库,一旦选中,应自动从数据库填充。如何在Jquery中使用自动完成。这是我的密码

Index.jsp `


函数myFun(){
//$.getJSON(“list.jsp”,{q:$(“#country”).val()},displayResult);
$.ajax({type:“POST”,url:“list.jsp”,
数据:“q=“+document.getElementById(“国家”)。值,
成功:函数(数据){$(“#txthint”).html(数据);};
};
国家:

`
list.jsp

`


`


提前感谢。

为此使用Ajax页面方法-这将帮助您调用服务器端函数,但是Jquery中的autocomplete呢@请访问此链接:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="jquery-ui.css" />
    <script type="text/javascript" src="jquery-1.11.2.min.js"></script>
    <script src="JS/jquery.autocomplete.js"></script>
    <script>

  function myFun() {


   //$.getJSON( "list.jsp",{q : $("#country").val()}, displayResult);
   $.ajax({type:"POST",url:"list.jsp",
   data:"q="+document.getElementById("country").value,
   sucess:function(data){$("#txthint").html(data);}});
};

</script>
</head>
<body>
    <div style="width: 300px; margin: 50px auto;">
        <b>Country</b>   : <input type="text" id="country" name="country" 
                        class="input_text" onkeyup="myFun()"/>

      <p id="txtHint"></p>
</body>
</html>`
<%@page import="java.io.PrintWriter"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import ="java.sql.*" %>

<% 
    out.println("came");
    try{
Class.forName("com.mysql.jdbc.Driver");
Connection connection;
       connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root");
   Statement statement = connection.createStatement() ;
       ResultSet rs;
      rs =statement.executeQuery("select * from sss where uname like '%"+request.getParameter("q")+"%';");

       while(rs.next())
       {

       out.println(rs.getString(1));

       }
    }
    catch(Exception e)
        {
             out.println("wrong entry"+e);
        }

%>