基于Jquery的Ajax方法

封装了jquery的ajax方法。

代码路径utiljs/jquery.util.js
代码:
function _ajax_execute(url, callback) {
    $.ajax({
        type : "post",
        url : url,
        dataType : "text",
        success : function(data, textStatus) {
            if (callback)
                callback(data);
        },
        error : function(data, textStatus, errorThrown) {
            
            if(errorThrown == 'Not Found'){
                //alert('页面为找到!');
            }else{
                // 请求出错处理
                alert("系统发生异常或登陆超时,请稍候再试!错误信息:\nXMLHttpRequest="
                        + data.responseText + "\ntextStatus=" + textStatus
                        + "\nerrorThrown=" + errorThrown);
            }
        }
    });
}  
应用举例:
通过ajax提交了表单,并判断是否返回成功。之后做了跳转和打开一个新窗口。
    function noticePrint(serialNo,caseId,writType){
        var url= "noticePrint.do?serialNo="+serialNo;
        _ajax_execute(url, function(responseText) {
            var objData = jQuery.parseJSON(responseText);
            if (objData.code==<%=ErrorCode.SUCCESS.ordinal()%>) {
                showBlock();
                location.href="queryNameList.do?caseId="+caseId;
                var tempUrl="printView.do?caseId="+caseId+"&writType="+writType;
                open(tempUrl);
            }
        });      
    }  





posted @ 2017-07-03 18:01  nobug的世界  阅读(131)  评论(0编辑  收藏  举报