如何使用AJAX在java中显示MYSQL的数据
我在mysql中有一个表,其中有三个字段插入了数据。其中有三个字段,如下所示。 我想使用java中的ajax在web浏览器上显示这些数据 我在网上搜索,发现下面的代码是最有用的如何使用AJAX在java中显示MYSQL的数据,java,mysql,ajax,jsp,servlets,Java,Mysql,Ajax,Jsp,Servlets,我在mysql中有一个表,其中有三个字段插入了数据。其中有三个字段,如下所示。 我想使用java中的ajax在web浏览器上显示这些数据 我在网上搜索,发现下面的代码是最有用的 Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/ajax_demo","root",""); PreparedStatement ps=con.prepareStatement("select * from ajax")
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/ajax_demo","root","");
PreparedStatement ps=con.prepareStatement("select * from ajax");
为了显示输出,我还必须实现哪些其他功能。您需要执行AJAX请求,AJAX请求的主要代码体如下
request.onreadystatechange=handleResponse;
request.open(typeReq, url, true);
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
request.send(queryString);
typeReq是请求的类型:POST或GET。
url:目标url地址。
queryString:要发送的数据集
HandlerResponse是处理响应的函数。例如:
function handleResponse () {
if (request.readyState = 4) {
if (request.status = 200) {
var response = request.responseText;
//code to handle response
} else {
//code to handle errors
}
}
现在,您可以使用prototype或jquery之类的API,这更简单
我希望这些信息对你有帮助
祝你好运将表命名为ajax只会让你感到困惑。Ajax只是一种javascript技术,用于向Web服务器上的页面发送HTTP请求。