forked from jakerella/jquery-mockjax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
54 lines (49 loc) · 1.1 KB
/
test.js
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
(function($) {
$(function() {
$.ajax({
url: 'test.json',
success: function(data) {
$('ul').append('<li>test.json: completed (' + data.test + ')</li>');
}
});
$.mockjax({
url: 'test.json',
contentType: 'text/json',
responseText: { "test": "mock message" }
});
$.ajax({
url: 'test.json',
dataType: 'json',
success: function(data) {
$('ul').append('<li>test.json: completed (' + data.test + ')</li>');
},
error: function(xhr, status, error) {
alert('error: ' + status + ' ' + error);
},
complete: function() {
}
});
$.mockjax({
url: 'http://google.com',
responseText: 'alert("Hello world");'
});
$.mockjax({
url: 'http://another-cross-domain.com',
responseText: function() {
alert("Get script mock");
}
});
$.ajax({
url: 'http://google.com',
dataType: 'script',
success: function(data) {
$('ul').append('<li>script: completed (' + data.test + ')</li>');
},
error: function(xhr, status, error) {
alert('error: ' + status + ' ' + error);
},
complete: function() {
}
});
});
})(jQuery);