-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAjaxServerResponseHander.min.js
9 lines (9 loc) · 2.52 KB
/
AjaxServerResponseHander.min.js
1
2
3
4
5
6
7
8
9
/*********************************************************************
* AjaxServerResponseHander *
* *
* Version: 1.0 *
* Date: 17-08-2020 *
* Author: Dan Machado *
* *
**********************************************************************/
var AjaxServerResponseHander=function(){var e={handlers:{},addEventHandler:function(e,t){this.handlers[e]=this.handlers[e]||[],this.handlers[e].push(t)},fire:function(e){var t=!1;for(var n in this.handlers[e])this.handlers[e][n].apply(null,Array.prototype.slice.call(arguments,1)),t=!0;return t}},s=Object.create(e);return function(){var t=function(e){};s.debug=function(e){t(e)};var o=function(){if(window.XMLHttpRequest)return function(){return new XMLHttpRequest};if(window.ActiveXObject)try{return new ActiveXObject("Msxml2.XMLHTTP"),function(){return new ActiveXObject("Msxml2.XMLHTTP")}}catch(e){try{return new ActiveXObject("Microsoft.XMLHTTP"),function(){return new ActiveXObject("Microsoft.XMLHTTP")}}catch(e){try{return new ActiveXObject("MSXML2.XMLHTTP.3.0"),function(){return new ActiveXObject("MSXML2.XMLHTTP.3.0")}}catch(e){s.debug("Bad ajax object!!")}}}}();function n(e,t,n){var r=o();r.onreadystatechange=function(){4==r.readyState&&(200==r.status?function(e){var t=null,n=JSON.parse(e);if(void 0!==n.textResponse)for(var r in n.textResponse)t=document.getElementById(r),n.textResponse.hasOwnProperty(r)&&null!=t?t.innerHTML=n.textResponse[r]:s.debug("Document does not have any element with ID: "+r);if(void 0!==n.Functions)for(var o in n.Functions)if(n.Functions.hasOwnProperty(o)){for(var i=window,a=o.split("."),c=0;c<a.length;c++)i=i[a[c]];if("function"==typeof i)for(c=0;c<n.Functions[o].length;c++)i.apply(null,n.Functions[o][c]);else s.debug(o+" is undefined")}}(r.responseText):s.fire("statusCode:"+r.status)||s.debug("Server responded with status code: "+r.status))};try{r.open("POST",t,!0),"Content-type"===n&&r.setRequestHeader("Content-type","application/x-www-form-urlencoded"),r.send(e)}catch(e){s.debug(e)}}s.submitForm=function(e,t){n(new FormData(document.forms.namedItem(e)),t,"no-header")},s.postData=function(e,t){n(e,t,"Content-type")},s.setDebugger=function(e){t="function"==typeof e?e:function(e){}},s.addServerFailHandler=function(e,t){s.addEventHandler(e,t)}}(),s}();