Javascript jsp中jQuery的远程验证
此表单将把手机号码插入我的MYSQL数据库 首先,我试图远程验证手机,以确保它不存在 脚本将写入数据库,但验证不起作用。我对JQ和Ajax还不熟悉,所以任何帮助都会受到欢迎 注意:所需的验证消息工作正常,但填写手机号码时已存在 然后单击SubmitNothing 谢谢 我的表格:Javascript jsp中jQuery的远程验证,javascript,jquery,jsp,validation,jquery-plugins,Javascript,Jquery,Jsp,Validation,Jquery Plugins,此表单将把手机号码插入我的MYSQL数据库 首先,我试图远程验证手机,以确保它不存在 脚本将写入数据库,但验证不起作用。我对JQ和Ajax还不熟悉,所以任何帮助都会受到欢迎 注意:所需的验证消息工作正常,但填写手机号码时已存在 然后单击SubmitNothing 谢谢 我的表格: <form name="form" id="form" action="check_phone.jsp" method="post"> <input type="text" name
<form name="form" id="form" action="check_phone.jsp" method="post">
<input type="text" name="mobile" id="mobile"/></br>
<input type="submit" />
</form>
我的JSP页面:
<%
Connection con;
Statement stm = null;
ResultSet rs;
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost/DB_NAME","root","root");
String mobile =request.getParameter("mobile");
stm=con.createStatement();
rs=stm.executeQuery("select * from student where mobile = '"+mobile+"'");
if(rs.next()) {
out.print("false"); //already exist
} else
{
out.print("true"); // not exist
}
}catch(SQLException e){
out.print(e);
}catch(ClassNotFoundException e){
out.print(e);
}
%>
感谢您对我的问题的回答,但是我遵循这些文档,正如我之前提到的,我是一个初学者[而不是在$document.readyfunction中进行验证{将其放入命名函数中,并让表单的onSubmit方法调用该函数。
<%
Connection con;
Statement stm = null;
ResultSet rs;
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost/DB_NAME","root","root");
String mobile =request.getParameter("mobile");
stm=con.createStatement();
rs=stm.executeQuery("select * from student where mobile = '"+mobile+"'");
if(rs.next()) {
out.print("false"); //already exist
} else
{
out.print("true"); // not exist
}
}catch(SQLException e){
out.print(e);
}catch(ClassNotFoundException e){
out.print(e);
}
%>