script.html
2.51 KB
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
<html>
<head>
<title>dojo/request/script</title>
<style type="text/css">
@import "../../resources/dojo.css";
</style>
<script>
var dojoConfig = {
async: true
};
</script>
<script type="text/javascript" src="../../dojo.js"></script>
<script type="text/javascript">
var request, fr;
require(["dojo/request/script", "dojo/errors/RequestTimeoutError", "dojo/errors/CancelError", "doh", "dojo/_base/window", "dojo/domReady!"], function(script, RequestTimeoutError, CancelError, doh, win){
doh.register("dojo/request/script", [
function load(t){
//t.is("undefined", typeof(scriptLoad));
var d = new doh.Deferred();
var td = script.get("scriptDummyMethod.php", {
query: {
scriptVar: "scriptLoad"
}
}).then(d.getTestCallback(function(data){
t.isNot("undefined", typeof scriptLoad);
t.is("loaded", scriptLoad);
}), function(error){
d.errback(error);
});
return d;
},
function checkString(t){
var d = new doh.Deferred();
script.get("scriptDummyMethod.php", {
query: {
checkString: "myTasks"
},
checkString: "myTasks"
}).then(d.getTestCallback(function(data){
t.isNot("undefined", typeof myTasks);
t.is("Do dishes.", myTasks[1]);
}), function(error){
d.errback(error);
});
return d;
},
function jsonp(t){
var d = new doh.Deferred();
script.get("scriptDummyMethod.php", {
query: { foo: "bar" },
jsonp: "callback"
}).then(d.getTestCallback(function(data){
t.is("mammal", data.animalType);
}), function(error){
d.errback(error);
});
return d;
},
function jsonpTimeout(t){
var d = new doh.Deferred();
script.get("scriptDummyMethod.php", {
query: { delay: 3 },
timeout: 500,
jsonp: "callback"
}).then(function(data){
d.errback(false);
}, d.getTestCallback(function(error){
t.t(error instanceof RequestTimeoutError);
}));
return d;
},
function jsonpCancel(t){
var d = new doh.Deferred();
script.get("scriptDummyMethod.php", {
query: { delay: 3 },
jsonp: "callback"
}).then(function(data){
d.errback(false);
}, d.getTestCallback(function(error){
t.t(error instanceof CancelError);
})).cancel();
return d;
}
]);
doh.run();
});
</script>
</head>
<body>
<h1>dojo/request/script test</h1>
</body>
</html>