diff options
Diffstat (limited to 'python/Dawn/static')
| -rw-r--r-- | python/Dawn/static/dawn.js | 21 | ||||
| -rw-r--r-- | python/Dawn/static/utils.js | 22 |
2 files changed, 26 insertions, 17 deletions
diff --git a/python/Dawn/static/dawn.js b/python/Dawn/static/dawn.js index a282d6c1..27d4ca3c 100644 --- a/python/Dawn/static/dawn.js +++ b/python/Dawn/static/dawn.js @@ -1,6 +1,3 @@ -function $(s){ - return document.getElementById(s) -} var index_list = []; var bbg_map = {'CDX': ["IG", "HY"], 'ITRX': ["EUR", "XOVER"]} var index_series = ["21", "23", "24", "25"]; @@ -16,21 +13,11 @@ for(var begin_index in bbg_map){ } }; -function callback(t) { - console.log(t); +function callback(data) { + data = JSON.parse(data); + console.log(data); }; -function query_id(secur_id) { - var xhr = new XMLHttpRequest(); - xhr.open('GET', "/_ajax?bbg_id="+encodeURIComponent(secur_id)); - xhr.onreadystatechange = function() { - if( xhr.readyState === 4 ){ - callback(xhr.responseText ); - } - } - xhr.send(); -} - var datalist = $('index_list'); index_list.forEach(function(item){ var option = document.createElement('option'); @@ -51,7 +38,7 @@ document.addEventListener("DOMContentLoaded", function(){ }); $('security_desc').setAttribute('list', 'index_list'); $('security_desc').addEventListener('change', function(){ - query_id(this.value); + query('../_ajax', {bbg_id: this.value}, callback); }); var event = new Event('change'); $('swap_type').dispatchEvent(event); diff --git a/python/Dawn/static/utils.js b/python/Dawn/static/utils.js new file mode 100644 index 00000000..0b886e8f --- /dev/null +++ b/python/Dawn/static/utils.js @@ -0,0 +1,22 @@ +function $(s) { + return( document.getElementById(s) ) +} + +function encode_dict(d){ + var r = [] + for(var k in d){ + r.push(encodeURIComponent(k) + '=' + encodeURIComponent(d[k])); + } + return r.join('&'); +} + +function query(url, params, callback){ + var xhr = new XMLHttpRequest(); + xhr.open('GET', url + '?' + encode_dict(params)); + xhr.onreadystatechange = function() { + if( xhr.readyState === 4){ + callback(xhr.responseText); + } + } + xhr.send(); +} |
