/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: Henrik G.
  • Date: 2013-03-26 23:22:55 UTC
  • Revision ID: henrik.gustavsson@his.se-20130326232255-ik6snyatlbkf3zs1
First seed of Lenasys ... Needs to be Organized Further

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
        }
 
116