admin
2022-01-07 8dfe5354073b700af45d5cb472dd5f003e6f3f25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//API_KEY && API_SIG for flickr
var API_KEY = "8873397f084b2390be0fca6d0058c937";
var API_SIG = "e78c1066099b5954";
 
var url = "http://192.168.1.101:8080/web/";
 
 
var PicasaMgr = {
 
        /**
         * return true if send successfully, else return false
         * 
         * data is a json object e.g. {a: "hello", b: "hi"}
         * 
         * callback(status), 
         */
        sendReport : function(data, type, callback){
            var reportData = data;                    
            
            if(!callback){
                callback = this._defaultCallback;
            }
            
            this._callback = callback;
        
            //send data timeout
            var timeOutId = setTimeout(this._requestTimeoutCallback, this._requestTimeout);
            
            var xmlHttpRequest = this._getXmlHttpRequest();
            alert(url);
            
            var reqParam = this._getRequestPara("POST", url);            
            
            xmlHttpRequest.open(reqParam.method, reqParam.url, reqParam.async);            
            xmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");        
            
            xmlHttpRequest.onreadystatechange = function(){
                clearTimeout(timeOutId);
                if(this.readyState == 4){    
                    alert(this.status);
                    callback(this.status == 200);
                }
            };
            
            try{
                alert("send : "+ reportData);
                xmlHttpRequest.send(reportData);
            }catch(e){
                alert("send error:  "+e);
            }
            
        },
        
        _requestTimeoutCallback: function(){
            var xmlHttp = Logger.Reporter._getXmlHttpRequest();            
            if(xmlHttp != null){
                xmlHttp.onreadystatechange = null;
                xmlHttp.abort(); //doesn't work correctly
                Logger.Reporter._callback(false);
            }
        },
        
        /**
         * do nothing
         */
        _defaultCallback : function(status){
            alert(status);            
        },
        
        _getRequestPara : function(_method,_url){
            return {method : _method, url: _url, async : true};
        },
        
        _getXmlHttpRequest : function(){            
            var xmlHttpRequest = null;
            
            if (window.XMLHttpRequest) {
                xmlHttpRequest = new XMLHttpRequest();
            } else {
                var MSXML = ['MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0',
                        'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];
                for ( var i = 0; i < MSXML.length; i++) {
                    try {
                        xmlHttpRequest = new ActiveXObject(MSXML[i]);
                    } catch (e) {
                    }
                }
            }
            
            return xmlHttpRequest;
        },
        
        _callback : null,
        _requestTimeout : 5000
};
 
function test() {
    PicasaMgr.sendReport("111");
}