equal
deleted
inserted
replaced
|
1 (function ($) { |
|
2 |
|
3 $.jsonRpc = $.jsonRpc || function (options) { |
|
4 options.type = options.type || 'GET'; |
|
5 var ajaxOptions = { |
|
6 contentType: 'application/json', |
|
7 dataType: options.type == 'GET' ? 'jsonp' : 'json', |
|
8 processData: options.type == 'GET' |
|
9 }; |
|
10 |
|
11 var data = { |
|
12 version: options.version || '1.0', |
|
13 method: options.method || 'system.listMethods', |
|
14 params: options.params || [] |
|
15 }; |
|
16 $.each(data, function (i) { |
|
17 delete options[i] |
|
18 }); |
|
19 |
|
20 function send() { |
|
21 options.data = JSON.stringify(data); |
|
22 if (options.type == 'GET') options.data = {json: options.data}; |
|
23 $.ajax($.extend(ajaxOptions, options)); |
|
24 } |
|
25 |
|
26 if (typeof JSON == 'undefined') { |
|
27 $.getScript('http://www.json.org/json2.js', function () { |
|
28 send() |
|
29 }); |
|
30 } else { |
|
31 send(); |
|
32 } |
|
33 return $; |
|
34 }; |
|
35 |
|
36 })(jQuery); |