jquery ajax 无刷新页面
2014-04-15 10:34
411 查看
jsp
<input type="button" class="button" value="保存" onclick="addCus()"/>
javascript
function addCus(){
var name = document.getElementById("customerName").value;
if(name == ""){
alert("提示:顾客姓名不能为空!");
return false;
}
$.ajax( {
url : "<%=request.getContextPath()%>/customer/findIsExistByName.action",
type : "POST",
cache : false,
async : false,
data : {
"customerName" : name
},
dataType : "json",
success : function(json) {
/* alert(json[0].sex); json中有几条数据 ,json.length 就有几条数据,直接循环读取其中内容*/
if(json.length != 0 || json != ""){
alert("此顾客姓名已经存在!请重新输入");
return false;
}else{
var conValue = confirm("提示:你正在添加顾客信息,是否确定?");
if(conValue){
with (document.getElementById("myform")) {
method = "post";
action = "<%=request.getContextPath()%>/customer/addCus.action";
submit();
}
}
}
}
});
}
struts_xml
<!-- 添加时候 ,判断顾客姓名是否存在 -->
<action name="findIsExistByName" class="CustomerAction" method="findIsExistByName">
<result name="success">/gk/gk_msg.jsp</result>
<result name="error">/card/error.jsp</result>
<result name="exception">/card/exception.jsp</result>
</action>
action
private String json;
public String findIsExistByName(){
try {
List<CustomerInfo> cusList = customerService.getListCusByName(customerName);
json = com.alibaba.fastjson.JSON.toJSONString(cusList);
} catch (Exception e) {
e.printStackTrace();
this.addActionError("错误提示:对不起,系统暂时不能处理您<br>的请求,请稍候重试或与系统管理员联系!");
return "exception";
}
return SUCCESS;
}
gk_msg.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
${json}
<input type="button" class="button" value="保存" onclick="addCus()"/>
javascript
function addCus(){
var name = document.getElementById("customerName").value;
if(name == ""){
alert("提示:顾客姓名不能为空!");
return false;
}
$.ajax( {
url : "<%=request.getContextPath()%>/customer/findIsExistByName.action",
type : "POST",
cache : false,
async : false,
data : {
"customerName" : name
},
dataType : "json",
success : function(json) {
/* alert(json[0].sex); json中有几条数据 ,json.length 就有几条数据,直接循环读取其中内容*/
if(json.length != 0 || json != ""){
alert("此顾客姓名已经存在!请重新输入");
return false;
}else{
var conValue = confirm("提示:你正在添加顾客信息,是否确定?");
if(conValue){
with (document.getElementById("myform")) {
method = "post";
action = "<%=request.getContextPath()%>/customer/addCus.action";
submit();
}
}
}
}
});
}
struts_xml
<!-- 添加时候 ,判断顾客姓名是否存在 -->
<action name="findIsExistByName" class="CustomerAction" method="findIsExistByName">
<result name="success">/gk/gk_msg.jsp</result>
<result name="error">/card/error.jsp</result>
<result name="exception">/card/exception.jsp</result>
</action>
action
private String json;
public String findIsExistByName(){
try {
List<CustomerInfo> cusList = customerService.getListCusByName(customerName);
json = com.alibaba.fastjson.JSON.toJSONString(cusList);
} catch (Exception e) {
e.printStackTrace();
this.addActionError("错误提示:对不起,系统暂时不能处理您<br>的请求,请稍候重试或与系统管理员联系!");
return "exception";
}
return SUCCESS;
}
gk_msg.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
${json}
相关文章推荐
- jquery ajax方式上传图片页面无刷新浏览
- jQuery ajax - load() 和setInterval()方法实现页面局部刷新
- 在同一个页面父窗口打开子窗口,动态无刷新提交,超炫基于jquery ajax提交,兼容IE7+,火狐..
- jquery ajax刷新局部页面,取得数据后,动态的在前台显示
- 关于使用Jquery Ajax点击checkbox 获取数据库 实现刷新当前页面
- django 用jquery ajax提交form 实现刷新部分页面
- dhl:asp.net mvc下用jQuery ajax方法实现无刷新分页(用户控件)& 整体页面无刷新(2010-11-13 add)
- Django1.6+jQuery Ajax + JSON 实现页面局部实时刷新
- jquery ajax无刷新页面上传
- jQuery Ajax异步刷新局部页面
- 利用JQUERY AJAX上传文件。重点是实现不刷新页面
- [日常折腾](一)jQuery AJAX刷新后闪回原页面
- jquery ajax 页面无刷新修改DOM----Thinkphp
- jquery ajax无刷新更新页面
- jquery ajax因异步设置不当导致页面局部内容(load())刷新不显示的问题总结
- jquery ajax调用不刷新页面
- 页面自动滚动到刷新页面之前的控件
- 使用layer的iframe层提交表单后,需要关闭当前的iframe层,然后刷新父页面的方法
- .NET页面回退刷新
- 页面刷新一次,加一次访客记录