-
Notifications
You must be signed in to change notification settings - Fork 8
/
webservices.fake.js
53 lines (45 loc) · 1.62 KB
/
webservices.fake.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
/*!------------------------------
* webservice.fake.js
* http://anasnakawa.github.com/jquery.ajax.fake
* license: MIT (http://opensource.org/licenses/mit-license.php)
* author : Anas Nakawa [email protected] @anasnakawa
* ------------------------------
*/
;(function($) {
var fake = $.ajax.fake;
// @use registerWebservice(path, callback [, method [, responseStatus]])
// @param {string} path - Path to the webservice
// @param {function} callback - A callback containing the return object with two states (success and error).
// @param {string} [method] - Optional. Request method.
// @param {string} [responseStatus] - Optional. What response will be returned (success, error).
// using default request type (get) and response status (success)
fake.registerWebservice('some/path/here', function( data ) {
var response = {
"success": {
"propOne": "valueOne",
"propTwo": 5,
"...": "..."
},
"error": {
"status": 500,
"responseText": "{\"error\": \"server_error\", \"message\": \"This is the error messaage\"}"
}
};
return response;
});
// force request type to 'post' and response status to what is set on dummy.js
fake.registerWebservice('some/path/here', function( data ) {
var response = {
"success": {
"propOne": "valueOne",
"propTwo": 5,
"...": "..."
},
"error": {
"status": 500,
"responseText": "{\"error\": \"server_error\", \"message\": \"This is the error messaage\"}"
}
};
return response;
}, 'post', dummyStatus);
})(jQuery);