-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
28 lines (27 loc) · 901 Bytes
/
api.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
(function($) {
// Define your custom plugin
$.api = function(options) {
// Default settings
var settings = $.extend({
url: '', // API endpoint URL
method: 'GET', // HTTP method (GET by default)
data: null, // Data to send (optional)
success: function(response) {
// Default success callback
console.log('API response:', response);
},
error: function(xhr, status, error) {
// Default error callback
console.error('Error:', status, error);
}
}, options);
// Make the API request using $.ajax
$.ajax({
url: settings.url,
method: settings.method,
data: settings.data,
success: settings.success,
error: settings.error
});
};
})(jQuery);