jnErrLevel=3; jconstErrLevelClient = 1; jconstErrLevelAdmin = 2; jconstErrLevelDebug = 3; jconstErrLevelNone = 4; constMsgAjaxResponseErrorStatus = 'Ошибка соединения с сервером\nСтатус ответа : '; constMsgAjaxResponseErrorEval = 'Error: eval exception.\nResponce : '; constMsgAjaxResponseErrorCode = 'Ошибка при выполнении запроса.\nКод : '; constMsgAjaxResponseErrorMsg = 'Ошибка : '; constMsgAjaxResponseErrorDetail = 'Описание : '; function jcAjax() { var prefixes = ["MSXML3", "MSXML2", "MSXML", "Microsoft"]; this.xmlHttp = false; this.method = "GET"; this.url = ""; this.fcallback = null; this.spost = null; this.resp = null; var ver = navigator.appName; var isFF=false; if (ver.indexOf("Netscape") != -1){isFF=true;} if((!this.xmlHttp) && (!isFF)) { for (var i = 0; i < prefixes.length; i++) { try { this.xmlHttp = new ActiveXObject(prefixes[i] + ".XMLHTTP"); break; } catch (e) { this.xmlHttp = null; } } } if (!this.xmlHttp || typeof XMLHttpRequest != 'undefined') { this.xmlHttp = new XMLHttpRequest(); } } jcAjax.prototype = { jfAjaxRequest : function(method, url, fcallback, noProgress) { this.method = method; this.url = url; this.fcallback = fcallback; var xmlHttp = this.xmlHttp; // Открыть соединение с сервером this.xmlHttp.open(this.method, this.url, true); if (this.method == "POST") { this.xmlHttp.setRequestHeader("Method", "POST " + this.url + " HTTP/1.1"); this.xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); //this.spost=encodeURIComponent(this.spost); } this.xmlHttp.onreadystatechange = function(){ var param; if (xmlHttp.readyState == 4) { $('ajaxLoadingDiv').style.display = 'none'; if(xmlHttp.status !=200 ) { alert(constMsgAjaxResponseErrorStatus+xmlHttp.status); return false; } var resp = xmlHttp.responseText; try { param = eval(resp)[0]; } catch (e) { alert(constMsgAjaxResponseErrorEval + resp); return false; }; if(param.errcode){ var err=constMsgAjaxResponseErrorCode+param.errcode; err=err+"\n"+constMsgAjaxResponseErrorMsg+param.errdescription; if(jnErrLevel!=jconstErrLevelClient) { err=err+"\n"+constMsgAjaxResponseErrorDetail+param.errdetail; } alert(err); if(jfGetInt(param.errcode)==666){ document.location.href = 'login.php'; } return false; } //alert(fcallback); fcallback(param); } } if (!noProgress) { $('ajaxLoadingDiv').style.top = Math.round(ScreenUtils.getHeight() / 2 + ScreenUtils.getScrollTop()) + 'px'; $('ajaxLoadingDiv').style.display = 'block'; } // Передать запрос this.xmlHttp.send(this.spost); }, //FILES UPLOAD iFrameRequest: function(rs, formID, callback,noProgress) { this.url = rs; this.fcallback = callback; this.getIFrame(); this.getIForm(formID); var thisObj = this; if (!noProgress) { $('ajaxLoadingDiv').style.top = Math.round(ScreenUtils.getHeight() / 2 + ScreenUtils.getScrollTop()) + 'px'; $('ajaxLoadingDiv').style.display = 'block'; } thisObj.getIForm().submit(); return true; }, iRunCallBack: function(){ var thisObj = this; $('ajaxLoadingDiv').style.display = 'none'; if($('ajax_cb').value == ''){return;} var resp = $('ajax_cb').value; try { param = eval(resp)[0]; } catch (e) { alert(constMsgAjaxResponseErrorEval + resp); return false; }; if(param.errcode){ var err=constMsgAjaxResponseErrorCode+param.errcode; err=err+"\n"+constMsgAjaxResponseErrorMsg+param.errdescription; if(jnErrLevel!=jconstErrLevelClient) { err=err+"\n"+constMsgAjaxResponseErrorDetail+param.errdetail; } alert(err); return false; } this.fcallback(param); return; }, getIFrame: function() { if (!this.iframe) { this.iframe = $('ajax_loading_ifarme'); } return this.iframe; }, getIForm: function(id) { if(id){ this.iform = $(id); this.iform.target = this.getIFrame().id; this.iform.action = this.url; this.iform.setAttribute('target', this.getIFrame().id); this.iform.setAttribute('action', this.url); } return this.iform; } } objAjax = new jcAjax();