20107 月29
buffalo ajax 实现表单提交
前台代码
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gbk"> <title>test</title> <LINK href="/wi/css/oa/blue/menu.css" type=text/css media=screen rel=stylesheet> <script language="javascript" src="/wi/script/prototype.js"></script> <script language="javascript" src="/wi/script/buffalo.js"></script> </head> <script language="javascript"> var endPointTop = '/wi/buffalo'; var waitingImg = '/wi/images/oa/loading.gif'; var loadingImg = '/wi/images/oa/loading.gif'; var userId = 'superadmin'; var deptId = '0001'; function test() { try { var user = Buffalo.Form.formToBean("form1", "modules.sys.Sys_user", true); var buffalo = new Buffalo(endPointTop); buffalo.remoteCall("desktopService.test", [userId,user], function(reply) { var str = reply.getResult(); alert(str); }); } catch (ex) { // alert(ex); } } </script> <body style="margin: 0; padding: 0; overflow: auto; " marginwidth="0" topmargin="0" leftmargin="0" marginheight="0"> <a href="#" onclick="test();">test</a> <form id ="form1"> <p>id:<input name="id" type="text" id="id"> name:<input name="name" type="text" id="name"> age: <input name="age" type="text" id="age"> memo: <input name="memo" type="text" id="memo"> </p> </form> </body> </html>
后台bean
public class User { private int id; private String name; private int age; private String memo; public User() { } //结合数据库操作可以添加 rs.getString 、get、set 方法 }
执行类
public class desktopService { public int test(String userId, Sys_user obj) { return 1; } }
buffalo缺点
实测过程中发现,buffalo实现form表单元素绑定是一对一的,form里包含多余的元素会报错。