日期:2014-05-16 浏览次数:20587 次
<%@ page language="java" pageEncoding="utf-8"%> <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%> <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%> <%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%> <%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <html:base /> <title>jquery_ajax.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="js/jquery.js"></script> <script type="text/javascript" src="js/jquery.form.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#login").click(function(){ $.ajax({ type:"get", url:"jquery.do?ope=doShow", data:'userName='+$("#usr").val()+"&pwd="+$("#pwd").val(), success:function(json){ var users = eval('(' + json + ')'); $.each(users,function(i,user){ $("#result").append(i+"name:"+user.itemName+"pwd:"+user.itemOp) }); } }) }); }) </script> </head> <body> <table border="0"> <tr> <td> Login: </td> <td> <input type="text" name="userName" id="usr" /> </td> </tr> <tr> <td> Password: </td> <td> <input type="text" id="pwd" name="pwd" /> </td> </tr> <tr> <td colspan="2" align="center"> <button id="login"> 登录 </button> </td> </tr> </table> <div id="result"></div> <form id="form2" action=""> //本来是打算一个页面放多个表单的,但是现在一个表单都没有搞定,那多个就只能放在一边了. </form> </body> </html>
<script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/jquery.form.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#login").click(function(){ var options = { target:"#result", type:"get", success:showResponse, resetForm:true, url:"jquery.do?ope=doShow"}; $("#myForm1").ajaxForm(options); }); function showResponse(xml){//回调函数 alert(xml); } }) </script> </head> <body> <form id="myForm1" method="post"> <table border="0"> <tr> <td> Login: </td> <td> <input type="text" name="userName" id="usr" /> </td> </tr> <tr> <td> Password: </td> <td> <input type="text" id="pwd" name="pwd" /> </td> </tr> <tr> <td colspan="2