App-Android(使用App+htnl5框架,解决消息推送兼容SignalR问题)
loulijun2021
2022-09-21 32383daed1b498577da8c37145e66e2a93e28b2d
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
<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="utf-8"/>
        <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
        <meta name="HandheldFriendly" content="true"/>
        <meta name="MobileOptimized" content="320"/>
        <title>Hello H5+</title>
        <script type="text/javascript" src="../js/common.js"></script>
        <script type="text/javascript">
var url="http://www.dcloud.io/";
var xhr=null;
 
function xhrCreate() {
    if ( xhr ) {
        outLine( "xhr请求已创建" );
        return;
    }
    outSet( "创建请求:" );
    xhr = new plus.net.XMLHttpRequest();
    xhr.onreadystatechange = function () {
        switch ( xhr.readyState ) {
            case 0:
                outLine( "xhr请求已初始化" );
            break;
            case 1:
                outLine( "xhr请求已打开" );
            break;
            case 2:
                outLine( "xhr请求已发送" );
            break;
            case 3:
                outLine( "xhr请求已响应");
                break;
            case 4:
                outLine( "xhr请求已完成");
                if ( xhr.status == 200 ) {
                    outLine( "xhr请求成功:"+xhr.responseText );
                } else {
                    outLine( "xhr请求失败:"+xhr.status );
                }
                break;
            default :
                break;
        }
    }
    xhr.open( "GET", url );
    xhr.send();
}
function xhrResponseHeader() {
    if ( xhr ) {
        if ( xhr.readyState != 4 ) {
            outLine( "xhr请求未完成" );
        } else if ( xhr.status != 200 ) {
            outSet( "xhr请求失败:"+xhr.readyState );
        } else {
            outSet( "xhr请求响应头数据:" );
            outLine( xhr.getAllResponseHeaders() );
        }
    } else {
        outSet( "未发送请求" );
    }
}
function xhrAbort() {
    if ( xhr ) {
        outSet( "取消请求" );
        if ( xhr.readyState != 4 ) {
            xhr.abort();
        }
        xhr = null;
    } else {
        outSet( "未发送请求" );
    }
}
        </script>
        <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8"/>
    </head>
    <body>
        <br/>
        <ul class="dlist">
            <li class="ditem" onclick="xhrCreate();">发送请求</li>
            <li class="ditem" onclick="xhrResponseHeader();">获取所有响应头</li>
            <li class="ditem" onclick="xhrAbort();">取消请求</li>
        </ul>
        <div id="outpos"/>
        <div id="output">
XMLHttpRequest管理网络请求操作,可进行跨域网络数据请求。
        </div>
    </body>
</html>