forked from jameslnewell/xhr-mock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
native.html
45 lines (33 loc) · 850 Bytes
/
native.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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Native Example — xhr-mock</title>
</head>
<body>
<h1>xhr-mock</h1>
<h2>Native Example</h2>
<script src="../build/build.js"></script>
<script>
var mock = require('xhr-mock');
mock.setup();
mock.get('http://google.com/', function(req, res) {
return res
.status(200)
.body('<h1>Google</h1>')
;
});
// ---------
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://google.com/');
xhr.onload = function() {
console.log('loaded', this.responseText);
};
xhr.onerror = function() {
console.log('error');
};
xhr.send();
// ---------
</script>
</body>
</html>