Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. var TQUERY = {
  3.         typeOf: function(object,type){
  4.             var typeArray = [];
  5.             if(typeof object.length === 'number' &&
  6.                 !(object.propertyIsEnumerable('length')) &&
  7.                 typeof object.splice === 'function'){
  8.                     if(type === 'array'){
  9.                         return true;
  10.                     }else if(typeof type === 'undefined'){
  11.                         return 'array';
  12.                     }else{
  13.                         return false;
  14.                     }
  15.             }
  16.            
  17.             if(typeof object == type){
  18.                     return true;
  19.             }else if(typeof object !== type){
  20.                 return false;
  21.             }else if(typeof type === 'undefined'){
  22.                 switch (typeof object) {
  23.                         case 'undefined':
  24.                         case 'object':
  25.                         case 'boolean':
  26.                         case 'number':
  27.                         case 'string':
  28.                                 return typeof object;
  29.                                 break;
  30.                         default:
  31.                                 return false;                        
  32.                 }
  33.             }
  34.            
  35.         },
  36.         testXMLHttpRequest: function(){
  37.             var xhr;
  38.             try {
  39.                 xhr = new ActiveXObject('Msxml2.XMLHTTP');
  40.             }catch (err2) {
  41.                 try {
  42.                     xhr = new ActiveXObject('Microsoft.XMLHTTP');
  43.                 }catch (err3) {
  44.                     try {
  45.                         xhr = new XMLHttpRequest();
  46.                     }
  47.                     catch (err1)
  48.                     {
  49.                         return false;
  50.                     }
  51.                 }
  52.             }
  53.             return xhr;
  54.         },
  55.         json : {
  56.             string : function(obj){
  57.                 try {
  58.                     var newObj = JSON.parse(obj);
  59.                     return newObj;
  60.                 }catch(e){
  61.                     return false;
  62.                 }
  63.             },
  64.             object : function(obj){
  65.                 try {
  66.                     var newObj = JSON.stringify(obj);
  67.                     return newObj;
  68.                 }catch(e){
  69.                     //will not return false.
  70.                     return false;
  71.                 }
  72.             }
  73.         },
  74.         ajax : function(options){
  75.            
  76.             if(this.typeOf(options) == 'object'){
  77.                
  78.                 if(options.type === null || options.type == ''){
  79.                     return false;
  80.                 }else if(options.url === null || options.url == ''){
  81.                     return false;              
  82.                 }else{
  83.                    
  84.                     if(options.async == 'undefined'){
  85.                         options.async = false;
  86.                     }
  87.                    
  88.                     var xhr = new this.testXMLHttpRequest();
  89.                    
  90.                     if(options.type == 'post' || options.type == 'POST'){
  91.                        
  92.                         if(this.typeOf(options.data) == 'object'){
  93.                             console.log(options.data);
  94.                             options.data = this.objString(options.data);
  95.                             console.log(options.data);
  96.                         }
  97.                        
  98.                         xhr.open(options.type, options.url, options.async);
  99.                         xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  100.                         xhr.send(options.data);
  101.                     }else{
  102.                         xhr.open(options.type, options.link, options.async);
  103.                         xhr.send(null);
  104.                     }
  105.                     return xhr.responseText;
  106.                 }
  107.             }else{
  108.                 return false;
  109.             }
  110.         },
  111.         objString: function(obj){
  112.             var string = 'start=true';
  113.             for(var data in obj) {
  114.                 string = string + '&' + data + '=' + obj[data];
  115.             }
  116.             string = string + '&end=true';
  117.             return string;
  118.         }
  119. };
  120.  
  121. var $ = TQUERY;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement