`
lihua-he
  • 浏览: 102309 次
  • 性别: Icon_minigender_2
  • 来自: 上海
社区版块
存档分类
最新评论

jquery ajax无刷新技术

阅读更多
//总结经验: Json 比dwr 用法好  dwr会将方法都暴漏在外面
1>Action层
public void dismissalTeacherOperation(){
String status = null;
boolean flag = false;
String[] cardIdStr = cardId.split(",");
String employId = cardIdStr[0];
String employStatus = cardIdStr[1];
if(employStatus.equals(Constants.EMPLOY_TEACHER_STATUS_NO)){
flag = employManager.dismissalTeacher(employId);
if(flag){
status = "{msg:'"+Constants.EMPLOY_TEACHER_STATUS_NO+"'}";
}else{
status = "{msg:'"+Constants.EMPLOY_TEACHER_STATUS_YES+"'}";
}
}
JSONObject jsonObject = JSONObject.fromObject(status);
this.sendCallBackValue(jsonObject.toString());
}

public void sendCallBackValue(String content){
HttpServletResponse response = this.getResponse();
        try {
response.getWriter().write(content);
} catch (IOException e) {
e.printStackTrace();
}
}

2>jsp页面
function employ(employId,employStatus,index){
var status=employStatus
var employCardId=employId+','+status;
document.selectEmployForm.divNum.value=index;
if(confirm("<s:text name='employ.judgeResult.shureEmploy'/>")){
jQuery.ajax({
url:"/eitp/employ/judgeResultOperation.html",
data:{cardId:employCardId},//传递参数
type : "post",
cache : false,
dataType : "json",
success:callback
});
}
return false;
}
function callback(data){
var index = document.selectEmployForm.divNum.value
var status = data.msg;//从action中传过来的状态值
var divStatusNum = "status"+index;
var emyployYesNum = "emyployYes"+index;
var employNoNum = "emyployNo"+index;
if(status==0){
document.getElementById(divStatusNum).innerHTML="<font color=\"green\"><s:text name='employ.judgeResult.employOffer'/></font>";
document.getElementById(emyployYesNum).innerHTML="<font color=\"#999999\"><s:text name='employ.judgeResult.employYes'/></font>";
document.getElementById(employNoNum).innerHTML="<font color=\"#999999\"><s:text name='employ.judgeResult.employNo'/></font>";
alert('<s:text name="employ.judgeResult.employOffer"/>');
}else if(status==4){
alert('<s:text name="employ.judgeResult.notEmployForNoAnsQuestion"/>');
}else if(status==5){
document.getElementById(divStatusNum).innerHTML="<font color=\"red\"><s:text name='employ.judgeResult.employNo'/></font>";
alert('<s:text name="employ.judgeResult.employNo"/>');
}else if(status==6){
alert('<s:text name="employ.judgeResult.priorEmploy"/>');
}
}

需要导
<script type="text/javascript" src="/eitp/scripts/jquery/jquery-1.3.2.js"></script>
<script type="text/javascript" src="/eitp/scripts/jquery/json2.js"></script>


//dwr
在dwr.xml中配置
<create creator="spring" javascript="moreScale">  导包时名字要与此一至
         <param name="beanName" value="moreScaleManager"/>   接口
         <include method="scale"/>     接口中的方法名
</create>
在application.service.xml中配置
在页面中调用
moreScale.scale(chooseOrderId,function(qb){
var status = qb.answerStatus;
        if(status==2){
            alert('<s:text name="test.sacle.no"/>');
        }else{
        window.open ('/eitp/test/viewScales.html?infoId='+chooseOrderId+'&scaleTemp='+scaleTemp, 'newwindow', 'height=400, width=600,

top=100, left=100, toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes,location=no, status=no');
        }
      });
导包
<script type="text/javascript" src="<s:url value='/dwr/interface/moreScale.js' />"></script>
<script type="text/javascript" src="<s:url value='/dwr/engine.js'/>"></script>
  • js.zip (38.7 KB)
  • 下载次数: 6
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics