function saveUser(){
$('#fm').form('submit',{//当提交表单时候,会发生submit事件
url: url,
onSubmit: function(){
return $(this).form('validate');
},
success: function(result){
var result = eval('('+result+')');
if (result.success){
$('#dlg1').dialog('close');
$('#dg').datagrid('reload');
} else {
$.messager.show({
title: 'Error',
msg: result.msg
});
}
}
});
}
<form id="fm" method="post" novalidate>
<div class="fitem">
<label>FirstName:</label>
<input name="firstname" class="easyui-validatebox" required="true">
</div>
<div class="fitem">
<label>lastname:</label>
<input name="lastname" class="easyui-validatebox" required="true">
</div>
<div class="fitem">
<label>Phone:</label>
<input name="phone">
</div>
<div class="fitem">
<label>Email:</label>
<input name="email" class="easyui-validatebox" validType="email">
</div>
</form>
</div>
<table id="dg" title="My Users" class="easyui-datagrid" style="margin:0,0,0,0"
url="list_jsp.jsp"
toolbar="#toolbar1" pagination="true"
rownumbers="true" fitColumns="true" singleSelect="true">
<thead>
<tr>
<th field="id" width="50">ID</th>
<th field="firstname" width="50">First Name</th>
<th field="lastname" width="50">Last Name</th>
<th field="phone" width="50">Phone</th>
<th field="email" width="50">Email</th>
</tr>
</thead>
只把用到的div贴了出来,谢谢各位啦。
表单提交,,,,,,,,,,,
保存 这是保存按钮,调用了saveUser函数,我把saveUser中的
url改成了save.jsp,
save.jsp中是对数据库添加的代码,而且测试可用。
但是就是点击保存按钮后,不调用save.jsp。
最后问题,如何在url中直接写src下面的某个类?
提交表单数据后,调用URL地址(可以是.action或.do类似的地址)和后台进行交互,判断后台返回的数据(后台返回的数据应该是json格式(“success”:“true”)),如果返回的是true则ID为dlg1的标签元素关闭,并ID为dg元素重新加载,否则显示出错误信息
saveUser是个函数,里面用JQuery语句封装了保存用户的操作。
调用之后会提交fm表单,包含验证、成功之后以及失败后的操作。
Do the submit action, the options parameter is an object which contains following properties:
url: the action URL
onSubmit: callback function before submit
success: callback function after submit successfuly
The example below shows how to submit a valid form and avoid duplicate submiting the form.
$.messager.progress(); // display the progress bar
$('#ff').form('submit', {
url: ...,
onSubmit: function(){
var isValid = $(this).form('validate');
if (!isValid){
$.messager.progress('close'); // hide progress bar while the form is invalid
}
return isValid; // return false will stop the form submission
},
success: function(){
$.messager.progress('close'); // hide progress bar while submit successfully
}
});
<%
user u=new user();
String firstname=request.getParameter("firstname");
String lastname=request.getParameter("lastname");
String phone=request.getParameter("phone");
String email=request.getParameter("email");
daoImpl dao=new daoImpl();
System.out.print(firstname+lastname+phone+email);
String result=dao.add(u);
%>
这是数据库操作的代码 控制台有打印。 数据库中没有存入,是不是格式的问题?
顾伟,你看一下,这么写URL肯定不对吧,怎么确定调用类中的哪个方法,加入说test中有个query方法返回的是json数据,怎么写呢?谢谢啦