/lenasys/0.1

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/0.1

« back to all changes in this revision

Viewing changes to trunk/WebGL and Benchmarking/httpAjax.js

  • Committer: galaxyAbstractor
  • Date: 2013-03-28 14:57:59 UTC
  • mto: (4.7.3 GammaBear)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: galaxyabstractor@gmail.com-20130328145759-5psrhd129qknkrw3
Cleaned up shitty code

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
 
                /*--------------------------------------------------------------------------------
3
 
                         AJAX Queue
4
 
                ----------------------------------------------------------------------------------*/            
5
 
 
6
 
                var AJAXQueue = new Array;
7
 
                var AJAXServiceRunning=false;
8
 
 
9
 
                var httpAjax = false;
10
 
 
11
 
                /*--------------------------------------------------------------------------------
12
 
                                AjaxService
13
 
                                
14
 
                                This is the only interface to the AJAX wrapper. This makes the ajax service 
15
 
                                browser agnostic and provides a single interface for all of the services.
16
 
                                
17
 
                                Each service uses a different url and a different parameter layout.
18
 
                                                                
19
 
                ----------------------------------------------------------------------------------*/
20
 
 
21
 
                function AjaxService(servicename,serviceparam){
22
 
                                
23
 
                                AJAXQueue.push(servicename);
24
 
                                AJAXQueue.push(serviceparam);
25
 
 
26
 
                                if(!AJAXServiceRunning){
27
 
                                                AJAXServiceRunning=true;
28
 
                                                var Aparam=AJAXQueue.pop();
29
 
                                                var Aservice=AJAXQueue.pop();
30
 
                                                AjaxServiceExec(Aservice,Aparam);
31
 
                                }                               
32
 
                }
33
 
 
34
 
                /*--------------------------------------------------------------------------------
35
 
                                AjaxService
36
 
                                
37
 
                                This is the only interface to the AJAX wrapper. This makes the ajax service 
38
 
                                browser agnostic and provides a single interface for all of the services.
39
 
                                
40
 
                                Each service uses a different url and a different parameter layout.
41
 
                                                                
42
 
                ----------------------------------------------------------------------------------*/
43
 
 
44
 
                function AjaxServiceExec(servicename,serviceparam){
45
 
 
46
 
                        // Parameters are set, initiate AJAX engine
47
 
                  if (window.XMLHttpRequest) {
48
 
                        httpAjax = new XMLHttpRequest();
49
 
                    if (httpAjax.overrideMimeType) {
50
 
                        httpAjax.overrideMimeType('text/xml');
51
 
                    }
52
 
                  }else if(window.ActiveXObject){
53
 
                                try{
54
 
                                        httpAjax = new ActiveXObject("Msxml2.XMLHTTP");
55
 
                                                }catch(e){
56
 
                                                        try{
57
 
                                                                httpAjax = new ActiveXObject("Microsoft.XMLHTTP");
58
 
                                }catch(e){
59
 
                                                                alert("Couldn�t build an AJAX instance.");
60
 
                                  return false;
61
 
                                                        }
62
 
                                                }
63
 
                                }
64
 
                                
65
 
                                // Send request to Server and initiate callback.
66
 
                                
67
 
                    try{
68
 
                                        httpAjax.onreadystatechange = getPage;
69
 
                    }catch(e){
70
 
//                                      alert("onreadystatechange didn�t go well!");
71
 
                                        return false;
72
 
                                }try{
73
 
                                        httpAjax.open('POST', servicename, true);
74
 
                                  httpAjax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
75
 
                    }catch(e){
76
 
//                                      alert("Couldn�t open url.");
77
 
                      return false;
78
 
                    }try{
79
 
                                                httpAjax.send(serviceparam);                            
80
 
                    }catch(e){
81
 
//                                      alert("Couldn�t send request.");
82
 
                                        return false;
83
 
                                }
84
 
                   
85
 
                         return true;
86
 
 
87
 
                }
88
 
 
89
 
                /*--------------------------------------------------------------------------------
90
 
                                getPage
91
 
 
92
 
                                This is the AJAX callback function. It detects the invoking service and handles
93
 
                                the reply from each service accordingly.                                
94
 
                                                                
95
 
                ----------------------------------------------------------------------------------*/
96
 
 
97
 
        function getPage() {
98
 
                                        
99
 
                if(httpAjax.readyState == 4){
100
 
 
101
 
                                str=httpAjax.responseText;
102
 
 
103
 
                                if(AJAXQueue.length>0){
104
 
                                                var Aparam=AJAXQueue.pop();
105
 
                                                var Aservice=AJAXQueue.pop();
106
 
                                                AjaxServiceExec(Aservice,Aparam);
107
 
                                }else{
108
 
                                                AJAXServiceRunning=false;                               
109
 
                                }
110
 
                                
111
 
                                return true;                            
112
 
                }else{
113
 
                        // If any other ready state than prepared, do nothing!
114
 
          }
115
 
        }
 
2
/*--------------------------------------------------------------------------------
 
3
AJAX Queue
 
4
----------------------------------------------------------------------------------*/            
 
5
 
 
6
var ajaxQueue = new Array;
 
7
var ajaxServiceRunning = false;
 
8
 
 
9
var httpAjax = false;
 
10
 
 
11
/*--------------------------------------------------------------------------------
 
12
AjaxService
 
13
 
 
14
This is the only interface to the AJAX wrapper. This makes the ajax service 
 
15
browser agnostic and provides a single interface for all of the services.
 
16
 
 
17
Each service uses a different url and a different parameter layout.
 
18
                                
 
19
----------------------------------------------------------------------------------*/
 
20
function AjaxService(servicename, serviceparam) {
 
21
 
 
22
        ajaxQueue.push(servicename);
 
23
        ajaxQueue.push(serviceparam);
 
24
 
 
25
        if(!ajaxServiceRunning) {
 
26
                ajaxServiceRunning = true;
 
27
                var aParam = ajaxQueue.pop();
 
28
                var aService = ajaxQueue.pop();
 
29
                ajaxServiceExec(aService, aParam);
 
30
        }                               
 
31
}
 
32
 
 
33
/*--------------------------------------------------------------------------------
 
34
AjaxService
 
35
 
 
36
This is the only interface to the AJAX wrapper. This makes the ajax service 
 
37
browser agnostic and provides a single interface for all of the services.
 
38
 
 
39
Each service uses a different url and a different parameter layout.
 
40
                                
 
41
----------------------------------------------------------------------------------*/
 
42
function ajaxServiceExec(servicename, serviceparam) {
 
43
 
 
44
        // Parameters are set, initiate AJAX engine
 
45
        if (window.XMLHttpRequest) {
 
46
                httpAjax = new XMLHttpRequest();
 
47
                if (httpAjax.overrideMimeType) {
 
48
                        httpAjax.overrideMimeType('text/xml');
 
49
                }
 
50
        } else if(window.ActiveXObject) {
 
51
                try {
 
52
                        httpAjax = new ActiveXObject("Msxml2.XMLHTTP");
 
53
                } catch(e) {
 
54
                        try {
 
55
                                httpAjax = new ActiveXObject("Microsoft.XMLHTTP");
 
56
                        } catch(e) {
 
57
                                alert("Couldn�t build an AJAX instance.");
 
58
                                return false;
 
59
                        }
 
60
                }
 
61
        }
 
62
 
 
63
        // Send request to Server and initiate callback.
 
64
        try {
 
65
                httpAjax.onreadystatechange = getPage;
 
66
                httpAjax.open('POST', servicename, true);
 
67
                httpAjax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
 
68
                httpAjax.send(serviceparam);            
 
69
        } catch(e) {
 
70
                //alert("onreadystatechange didn�t go well!");
 
71
                return false;
 
72
        }
 
73
 
 
74
        return true;
 
75
 
 
76
}
 
77
 
 
78
/*--------------------------------------------------------------------------------
 
79
getPage
 
80
 
 
81
This is the AJAX callback function. It detects the invoking service and handles
 
82
the reply from each service accordingly.                                
 
83
                
 
84
----------------------------------------------------------------------------------*/
 
85
function getPage() {
 
86
 
 
87
        if(httpAjax.readyState == 4) { 
 
88
 
 
89
                str = httpAjax.responseText;
 
90
 
 
91
                if(ajaxQueue.length>0) {
 
92
                        var Aparam = ajaxQueue.pop();
 
93
                        var Aservice = ajaxQueue.pop();
 
94
                        ajaxServiceExec(Aservice, Aparam);
 
95
                } else {
 
96
                        ajaxServiceRunning=false;                               
 
97
                }
 
98
 
 
99
                return true;                            
 
100
        } else {
 
101
        // If any other ready state than prepared, do nothing!
 
102
        }
 
103
}
116
104