Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var TQUERY = {
- typeOf: function(object,type){
- var typeArray = [];
- if(typeof object.length === 'number' &&
- !(object.propertyIsEnumerable('length')) &&
- typeof object.splice === 'function'){
- if(type === 'array'){
- return true;
- }else if(typeof type === 'undefined'){
- return 'array';
- }else{
- return false;
- }
- }
- if(typeof object == type){
- return true;
- }else if(typeof object !== type){
- return false;
- }else if(typeof type === 'undefined'){
- switch (typeof object) {
- case 'undefined':
- case 'object':
- case 'boolean':
- case 'number':
- case 'string':
- return typeof object;
- break;
- default:
- return false;
- }
- }
- },
- testXMLHttpRequest: function(){
- var xhr;
- try {
- xhr = new ActiveXObject('Msxml2.XMLHTTP');
- }catch (err2) {
- try {
- xhr = new ActiveXObject('Microsoft.XMLHTTP');
- }catch (err3) {
- try {
- xhr = new XMLHttpRequest();
- }
- catch (err1)
- {
- return false;
- }
- }
- }
- return xhr;
- },
- json : {
- string : function(obj){
- try {
- var newObj = JSON.parse(obj);
- return newObj;
- }catch(e){
- return false;
- }
- },
- object : function(obj){
- try {
- var newObj = JSON.stringify(obj);
- return newObj;
- }catch(e){
- //will not return false.
- return false;
- }
- }
- },
- ajax : function(options){
- if(this.typeOf(options) == 'object'){
- if(options.type === null || options.type == ''){
- return false;
- }else if(options.url === null || options.url == ''){
- return false;
- }else{
- if(options.async == 'undefined'){
- options.async = false;
- }
- var xhr = new this.testXMLHttpRequest();
- if(options.type == 'post' || options.type == 'POST'){
- if(this.typeOf(options.data) == 'object'){
- console.log(options.data);
- options.data = this.objString(options.data);
- console.log(options.data);
- }
- xhr.open(options.type, options.url, options.async);
- xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
- xhr.send(options.data);
- }else{
- xhr.open(options.type, options.link, options.async);
- xhr.send(null);
- }
- return xhr.responseText;
- }
- }else{
- return false;
- }
- },
- objString: function(obj){
- var string = 'start=true';
- for(var data in obj) {
- string = string + '&' + data + '=' + obj[data];
- }
- string = string + '&end=true';
- return string;
- }
- };
- var $ = TQUERY;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement