-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathasync.html
93 lines (93 loc) · 2.41 KB
/
async.html
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
<html>
<head>
<meta charset="UTF-8">
<title>wechat js api async test - weAPI</title>
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no,minimal-ui" name="viewport" />
<script src="debug.js"></script>
<script src="weAPI.js?v=3"></script>
<script src="plugin/plugin.js?v=3"></script>
<script src="http://qunarzz.com/jquery/prd/jquery-1.7.2.js"></script>
<style type="text/css">
body{
font-size: 20px;
}
</style>
</head>
<body>
<a onclick="location.search='?'+(+new Date())">reload</a>
<p>分享数据来源是异步</p>
</body>
<script>
function _log(msg) {
// alert(msg)
}
var list = [
[
"shareTimeline", "朋友圈",
{
"appid":"",
"img_width":"640",
"img_height":"640",
title:"有趣的图片",
desc:"这是一张搞笑的图片,呵呵呵呵",
img_url: "http://file5.u148.net/2014/10/images/1412934017UEH.jpg",
link: "http://file5.u148.net/2014/10/images/1412934017UEH.jpg"
}
],
[
"shareToFriend",
"微信好友",
{
title:"有趣的图片",
img_url: "http://file5.u148.net/2014/10/images/1412934017UEH.jpg",
link: "http://file5.u148.net/2014/10/images/1412934017UEH.jpg"
}
],
[
"shareWeibo",
"微博",
{
content: "有趣的图片",
url: "http://file5.u148.net/2014/10/images/1412934017UEH.jpg"
}
]
]
weAPI.ready(function() {
for(var i in list) {
(function() {
var o = list[i]
if(weAPI[o[0]]) {
var name = o[1]
var h = weAPI[o[0]](o[2], {
async: true
}).ready(function(data, argv) {
var api = this
$.ajax({
type:"get",
dataType: "json",
url: "data.js?v=4",
success: function(res){
if(res[o[0]]) {
api.action(res[o[0]], argv)
} else {
alert(res)
}
}
})
}).cancel(function() {
_log(name + "cancle")
}).success(function() {
_log(name + "success")
}).fail(function() {
_log(name + "fail")
}).done(function(r) {
_log(name + "done" + (r ? "-" + JSON.stringify(r) : ""))
})
}
})()
}
})
</script>
</html>