/**
融汇兴业rewinAjax对象.
**/
/**
---修改记录
2000.xx.xx 陈宏建 建立文件,1.0版
2010.09.29 caifeng 增加部分备注文字,增加超时显示,增加debug开关,增加请求页面的随机数,修改分页计算的bug
---外部api调用
new rewinjson.rewinAjax("/classHTML/"+classid+".html",
new rewinjson.tool.parameter("","","",""),
rewinjson.client.InfoListMoreText,
"POST",
"rewinjson_info_45",
rewinjson.client.error
);
**/
var showDebug = false; //false; //是否现实调试信息
var useTimeOut = false; //false; //true; //是否现实调试信息
var time = 5000 ; //超时时间 ms
var divObj; //页面divid,用于控制显示页面提示
var timer; //定时器控件
var pageclassid;//切换的calssid
if(showDebug) alert("加载文件rewinAJAX.js")
/**
融汇兴业rewinAjax对象.
**/
rewinjson = {version: '1.0'};
rewinjson.client = new Object();
rewinjson.tool = new Object();
//请求数据主函数
/**
入参:
url: 请求的页面
para 参数
method 请求的方法
reqtype
obj 回写的页面divid
errMethod 发生错误时执行的方法
objName
*/
rewinjson.rewinAjax = function(url, param, method, reqType, obj,errMethod,objName)
{
if(showDebug) alert("rewinAjax: url= "+url)
if(showDebug) alert("rewinAjax: url= "+url +"----param="+param+"----method="+"----reqType="+reqType+"----obj="+obj+"----errMethod="+errMethod+"----objName="+objName)
divObj = obj ;////2010.9 对象保存 cf
this.obj = rewinjson.tool.$(obj);
this.url = url+"?t="+Math.random()*10; // 2010.9 增加随即数 cf
if(showDebug) alert("rewinAjax: this.url= "+this.url); //2010.9 cf
this.method = method;
this.errMethod=errMethod;
this.parameter = param;//eval('('+param+')');
this.objName = objName;
var _paramStr = null;
this.ajaxType = this.parameter.type.toLowerCase();//是
var rewinjson_divnum = obj.substring(obj.lastIndexOf("_")+1);
var rewinjson_divBase = obj.substring(0,obj.lastIndexOf("_")+1);
if(this.ajaxType.indexOf("json") != -1){//是以json请求
_paramStr = this.parameter.parameter;//将参数拼成一个串
_paramStr += "&datalen="+rewinjson_divnum;
temphrefurl = this.parameter.hrefURL;
temphrefurl = rewinjson.tool.base64encode(rewinjson.tool.strUnicode2Ansi(temphrefurl));
_paramStr += "&hrefURL="+temphrefurl;
tempfilter = this.parameter.filter;
//tempfilter = rewinjson.tool.base64encode(rewinjson.tool.strUnicode2Ansi(tempfilter));
tempfilter = rewinjson.tool.base64encode(encodeURI(tempfilter));
//alert(tempfilter);
_paramStr += "&filter="+tempfilter;
_paramStr += "&jsontype="+this.ajaxType;
}else{//带样式的请求
_paramStr = this.parameter.parameter;//将参数拼成一个串
temphrefurl = this.parameter.hrefURL;
temphrefurl = rewinjson.tool.base64encode(rewinjson.tool.strUnicode2Ansi(temphrefurl));
_paramStr += "&hrefURL="+temphrefurl;
tempfilter = this.parameter.filter;
tempfilter = rewinjson.tool.base64encode(rewinjson.tool.strUnicode2Ansi(tempfilter));
_paramStr += "&filter="+tempfilter;
}
this.req = null;
if(!isNaN(rewinjson_divnum)){
var tempNum = Math.floor(parseInt(rewinjson_divnum)/2);
for(var k = 0 ;k < tempNum; k ++){
rewinjson.tool.$(rewinjson_divBase+k).innerHTML = " ";
}
for(var k = tempNum+1 ;k < parseInt(rewinjson_divnum); k ++){
rewinjson.tool.$(rewinjson_divBase+k).innerHTML = " ";
}
if(rewinjson_divnum != undefined && rewinjson_divnum != null && rewinjson_divnum != ""){
rewinjson.tool.$(rewinjson_divBase+tempNum).innerHTML = "
数据正在加载,请稍侯......";
}else{
;
}
}else{
if(obj=="rewinjson_left"){
//this.obj.innerHTML = "
数据正在加载,请稍侯......";
}else{
//this.obj.innerHTML = "
数据正在加载,请稍侯......";
}
}
//初始化 请求对象,成员变量
if (window.XMLHttpRequest)
{
this.req=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
this.req=new ActiveXObject("Microsoft.XMLHTTP");
}
if (this.req)
{
try
{
var loader=this;
//状态每改变一次,就调用一次
this.req.onreadystatechange=function()
{
rewinjson.rewinAjax.onReadyState.call(loader); //把 rewinjson.rewinAjax.onReadyState 方法放到 rewinjson.client.InfoListMoreText 执行!
}
var _method = reqType.trim();
_method = _method.toLowerCase();
if(useTimeOut) timer = setTimeout("ontimeout()",time);//2010.9 设置超时定时器, n秒后执行ontimeout cf
if(_method == "post"){
this.req.open("POST",url,true);
this.req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
this.req.setRequestHeader("charset","UTF-8");
this.req.send(_paramStr);
}else{
this.url = url + "?" + _paramStr;
this.req.open("GET",this.url,true);
this.req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
this.req.setRequestHeader("charset","UTF-8");
this.req.send(null);
}
///
//this.req.open("post",this.url,true);
//this.req.send(this.url);
}
catch (err)
{
//alert(err+"ssss");
throw err;
}
}
}
//接受返回数据函数 内部
//因为被放到上面的函数中执行了,所以 this 是上面函数中的,而非此函数的
rewinjson.rewinAjax.onReadyState = function()
{
if (this.req.readyState==4)
{
var httpStatus=this.req.status;
if (httpStatus==200 || httpStatus==0)
{
if(useTimeOut) window.clearTimeout(timer); ////2010.9 正常返回数据后,清计超时时器 cf
if (this.method)
{
if(this.objName){
this.method(this.req.responseText, this.obj,this.objName);
}else{
this.method(this.req.responseText, this.obj);
}
}
/*try{
eval(this.errMethod)();
}catch(err){}*/
}else if(httpStatus == 404){
//alert("404")
try{
if(this.errMethod){
this.errMethod(this.obj,this.method,this.parameter);
}
}catch(err){}
}
}
}
//第二种ajax主要用于带选项卡的 内部
/**
入参:
url: 请求的页面
para 参数
method 请求的方法
reqtype
obj 回写的页面divid
tabName
*/
rewinjson.rewinAjax_tab = function(url, param, method, reqType, obj,tabName)
{
if(showDebug) alert("rewinAjax: url= "+url)
if(showDebug) alert("rewinAjax: url= "+url +"----param="+param+"----method="+"----reqType="+reqType+"----obj="+obj+"----errMethod="+errMethod+"----objName="+objName)
divObj = obj ;////2010.9 对象保存 cf
this.obj = rewinjson.tool.$(obj);
this.url = url+"?t="+Math.random()*10; // 2010.9 增加随即数 cf
this.method = method;
this.tabName = tabName;
this.parameter = param;//eval('('+param+')');
var _paramStr = null;
this.ajaxType = this.parameter.type.toLowerCase();//是
var rewinjson_divnum = obj.substring(obj.lastIndexOf("_")+1);
var rewinjson_divBase = obj.substring(0,obj.lastIndexOf("_")+1);
if(this.ajaxType.indexOf("json") != -1){//是以json请求
_paramStr = this.parameter.parameter;//将参数拼成一个串
_paramStr += "&datalen="+rewinjson_divnum;
temphrefurl = this.parameter.hrefURL;
temphrefurl = rewinjson.tool.base64encode(rewinjson.tool.strUnicode2Ansi(temphrefurl));
_paramStr += "&hrefURL="+temphrefurl;
tempfilter = this.parameter.filter;
tempfilter = rewinjson.tool.base64encode(rewinjson.tool.strUnicode2Ansi(tempfilter));
_paramStr += "&filter="+tempfilter;
_paramStr += "&jsontype="+this.ajaxType;
}else{//带样式的请求
_paramStr = this.parameter.parameter;//将参数拼成一个串
temphrefurl = this.parameter.hrefURL;
temphrefurl = rewinjson.tool.base64encode(rewinjson.tool.strUnicode2Ansi(temphrefurl));
_paramStr += "&hrefURL="+temphrefurl;
tempfilter = this.parameter.filter;
tempfilter = rewinjson.tool.base64encode(rewinjson.tool.strUnicode2Ansi(tempfilter));
_paramStr += "&filter="+tempfilter
}
this.req = null;
if(!isNaN(rewinjson_divnum)){
var tempNum = Math.floor(parseInt(rewinjson_divnum)/2);
for(var k = 0 ;k < tempNum; k ++){
if(rewinjson.tool.$(rewinjson_divBase+k) != undefined)
rewinjson.tool.$(rewinjson_divBase+k).innerHTML = " ";
}
for(var k = tempNum+1 ;k < parseInt(rewinjson_divnum); k ++){
if(rewinjson.tool.$(rewinjson_divBase+k) != undefined)
rewinjson.tool.$(rewinjson_divBase+k).innerHTML = " ";
}
if(rewinjson.tool.$(rewinjson_divBase+tempNum) != undefined)
rewinjson.tool.$(rewinjson_divBase+tempNum).innerHTML = "
数据正在加载,请稍侯......";
else
this.obj.innerHTML = "
数据正在加载,请稍侯......";
}else{
this.obj.innerHTML = "
数据正在加载,请稍侯......";
}
if (window.XMLHttpRequest)
{
this.req=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
this.req=new ActiveXObject("Microsoft.XMLHTTP");
}
if (this.req)
{
try
{
var loader=this;
this.req.onreadystatechange=function()
{
rewinjson.rewinAjax.onReadyState.call(loader);
}
var _method = reqType.trim();
_method = _method.toLowerCase();
if(useTimeOut) timer = setTimeout("ontimeout()",time);//2010.9 设置超时定时器, n秒后执行ontimeout cf
if(_method == "post"){
//alert(_paramStr);
this.req.open("POST",url,true);
this.req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
this.req.setRequestHeader("charset","GBK");
this.req.send(_paramStr);
}else{
this.url = url + "?" + _paramStr;
this.req.open("GET",this.url,true);
this.req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
this.req.setRequestHeader("charset","GBK");
this.req.send(null);
}
///
//this.req.open("post",this.url,true);
//this.req.send(this.url);
}
catch (err)
{
//alert(err);
}
}
}
/*********************************
以下为2010.9.29 新增,增加超时信息现实
*********************************/
//输出信息 内部函数 cf
function showTempInfo(info){
//alert("showTempImfo")
var rewinjson_divnum = divObj.substring(divObj.lastIndexOf("_")+1);
var rewinjson_divBase = divObj.substring(0,divObj.lastIndexOf("_")+1);
if(!isNaN(rewinjson_divnum)){
var tempNum = Math.floor(parseInt(rewinjson_divnum)/2);
for(var k = 0 ;k < tempNum; k ++){
rewinjson.tool.$(rewinjson_divBase+k).innerHTML = " ";
}
for(var k = tempNum+1 ;k < parseInt(rewinjson_divnum); k ++){
rewinjson.tool.$(rewinjson_divBase+k).innerHTML = " ";
}
if(rewinjson_divnum != undefined && rewinjson_divnum != null && rewinjson_divnum != ""){
rewinjson.tool.$(rewinjson_divBase+tempNum).innerHTML = info;
}else{
}
}else{
if(divObj=="rewinjson_left"){
divObj.innerHTML = info;
}else{
divObj.innerHTML = info;
}
}
}
//显示超时信息 内部函数 cf
function showTempInfoTimerOut(){
showTempInfo(" 数据超时或服务器忙,请您刷新页面或稍后再试......")
}
//超时处理 内部 cf
function ontimeout(){
if(showDebug) alert("ontimeout")
showTempInfoTimerOut()
window.clearTimeout(timer);//销毁定时器
}
/*
*本页跳转
*
*/
function getnew_page(newpage){
window.location=newpage;
}
/**
判断是否为数字
*/
function isInteger(obj){
reg=/^[-+]?\d+$/;
if(!reg.test(obj)){
return false;
}else{
return true;
}
}
function CreateScript_fx(){
//alert(url_wd);
var url_wd = document.referrer;
var new_element;
new_element=document.createElement("script");
new_element.setAttribute("type","text/javascript");
new_element.setAttribute("src","/gkzq/public/filter.jsp?RefererUrl="+url_wd);
if(document.body){
document.body.appendChild(new_element);
}else{
document.appendChild(new_element);
}
}
CreateScript_fx();