jsp 用 AJAX 跟 jQeury 的问题
程序代码:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>doreg.jsp</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> <script type="text/javascript" src="../script/jquery-1.7.1.js"></script> <script type="text/javascript"> $(function(){ $("input[name=button]").click(function(){ var username = $("input[name=username]").val(); var sex = $("input[name=sex]:checked").val(); var age = $("input[name=age]").val(); var important = $("select[name=important] option:selected").val(); var tag = $("input[name=tag]").val(); var data={ "username":username, "sex":sex, "age":age, "important":important, "tag":tag }; $.post("JSdoreg.jsp",data,function(data,state){ if(status == "success"){ alert(data.msg); window.location.href="register.jsp"; }else{ alert("添加失败!"); } },"json"); }); }); </script> </head> <body> <form style="text-align:center;" method="post"> 用户id:<input type="text" name="userid" id="userid" > <span id="info"></span><br /> 用户名:<input type="text" name="username"><br /> 性别:<input type="radio" name="sex" value="1">男 <input type="radio" name="sex" value="2">女 <br /> 年龄:<input type="text" name="age"><br /> 等级:<select name="important"> <option>重要的</option> <option>次要的</option> <option selected="selected">忽略的</option> </select> <br /> 标签:<input type="text" name="tag"><br /> <input type="button" name="button" value="确定"> </form> </body> </html>