【发布时间】:2018-07-13 16:17:33
【问题描述】:
我正在使用此 js 代码向 html 表添加新行并添加 ajax() 调用以使用 Jquery UI 自动完成
trd += "<tr>";
trd += "<td id='table_id' name='table_id' style='width: 10px; text-align: center; vertical-align:middle; display:none ;'></td>";
var appendCustodianTxt = "<td name='cus'><input class='form-control custodianautocomplete' name='custodianID' type='text' placeholder='Custodian' required/></td>";
trd += appendCustodianTxt;
trd += "</tr>";
$("table tbody").append(trd);
$("tr").find("cus").append(appendCustodianTxt);
$('.custodianautocomplete').autocomplete({
source: "./emplist.jsp"
}).focus(function() { $(this).find('input').select(); $(this).select(); });
emplist.jsp代码是这样的
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="com.mysql.*" %>
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<%
try{
String s[]=null;
Class.forName("com.mysql.jdbc.Driver"); // MySQL database connection
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/chbs?" + "user=root&password=rama30");
Statement stmt=conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from users");
List rowValues = new ArrayList();
while (rs.next()) {
rowValues.add(rs.getString("users.Employee_ID"));
}
contactListNames = (String[]) rowValues.toArray(new String[rowValues.size()]);
//response.getWriter().println(json_encode(contactListNames));
response.getWriter().println(contactListNames);
rs.close();
stmt.close();
conn.close();
}
catch(Exception e){
e.printStackTrace();
}
%>
我在 Console.log 中收到此错误
jquery-3.2.1.min.js:3049 GET http://localhost:8091/chbs/adm/emplist.jsp?term=1 500 (Internal Server Error)
我正在努力,但无法实现自动完成的结果。我没有使用 Eclipse,而是直接使用文本编辑器进行编码。请告知错误在哪里。
【问题讨论】:
-
看来,和 PHP 中的不一样... :(
标签: mysql jsp autocomplete