ajax页面异步刷新
展开全部
使用ajax 啊,100%满足你的需求!
下面我提供饥亮枝一个异步请求源代码给你 js中:
function isExist() {
var companyName = $("#company").val();
if(companyName==""){
alert("'所属公司'不烂敏能为空!");
$("#company").focus();
return;
}
var num = 0;
$.ajax({
url:"isExistCompany.do?company.companyName="+companyName+"&t="+new Date(),
async: false,
success:function(data) {
num = data;
}
});
if(num==0) {
alert("您键升输入的公司不存在,请重新输入!");
$("#company").val("")
$("#company").focus();
return false;
}
return true;
}
action中:public void isExistCompany() {
try {
int num = 0;
String companyName = company.getCompanyName();
if (company!=null|| StringUtil.notEmpty(companyName))
num=companyService.getCompanyId(companyName);
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/plain; charset=GBK");
PrintWriter out = response.getWriter();
out.print(num);
out.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
下面我提供饥亮枝一个异步请求源代码给你 js中:
function isExist() {
var companyName = $("#company").val();
if(companyName==""){
alert("'所属公司'不烂敏能为空!");
$("#company").focus();
return;
}
var num = 0;
$.ajax({
url:"isExistCompany.do?company.companyName="+companyName+"&t="+new Date(),
async: false,
success:function(data) {
num = data;
}
});
if(num==0) {
alert("您键升输入的公司不存在,请重新输入!");
$("#company").val("")
$("#company").focus();
return false;
}
return true;
}
action中:public void isExistCompany() {
try {
int num = 0;
String companyName = company.getCompanyName();
if (company!=null|| StringUtil.notEmpty(companyName))
num=companyService.getCompanyId(companyName);
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/plain; charset=GBK");
PrintWriter out = response.getWriter();
out.print(num);
out.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询