Note that there are some explanatory texts on larger screens.

plurals
  1. POHow Get JSON value and re-use it in many function?
    primarykey
    data
    text
    <p>Now it work... but how i can write the right call for the json?</p> <p>i tried with this direct link but doesn't work, maybe i've to edit the "data" parameters? I don't know because i read that is on optional parameter right? any help?</p> <p>And ho w i can set the continuous refres of the json values that i want to pick to make them always updated (every 60s).</p> <p>thanks!!</p> <pre><code>function itemManager(){ var _me = null; var _goldAsk = 0; var _silverAsk = 0; var _eurusdAsk = 0; var construct = function(){ //init here _me = $(this); _bindHandlers(); _updateItem(125); } var _bindHandlers = function(){ _me.on('stockupdated', function(){ $('#gcost').text(_goldAsk + ' ' + _silverAsk + ' ' + _eurusdAsk); }); $('#calculate').on('click', function(){ alert("item gold ask(" + _goldAsk + ") vs silver ask(" + _silverAsk + ")"); }); $('#updateitem').on('click', function(){ _updateItem(250); }); $('#btnGetTotals').on('click', function(){ var grammsOfGold = $('#goldGramms').val().length ? parseInt($('#goldGramms').val()) : 0; var grammsOfSilver = $('#silverGramms').val().length ? parseInt($('#silverGramms').val()) : 0; var carati = document.getElementById("carati").selectedIndex; alert('Total for gold: ' + (((( _goldAsk / 31.1034768 ) / _eurusdAsk) * (document.getElementsByTagName("option")[carati].value)) * grammsOfGold ).toFixed(2) + ' total for silver: ' + (grammsOfSilver * _silverAsk) + 'Carati selezionati: ' + (document.getElementsByTagName("option")[carati].value)) }); $('#btnGetInfo').on('click', function(){ alert('Gold ask: ' + ((_goldAsk / 31.1034768) / _eurusdAsk).toFixed(3) + ' silver ask: ' + ((_silverAsk / 31.1034768) / _eurusdAsk).toFixed(3)); }); } var _getMonth = function(){ return parseInt($('#month').val()); } var _updateItem = function(cost){ $.ajax({ type: 'POST', url: 'https://quotes.instaforex.com/get_quotes.php?m=json&amp;q=gold,silver,eurusd', data: { json: '{' + '"GOLD":{"symbol":"GOLD","lasttime":1379116798,"digits":2,"change":"-0.09","bid":"1325.91","ask":"1326.51"},' + '"SILVER":{"symbol":"SILVER","lasttime":1379116779,"digits":3,"change":"-0.010","bid":"22.170","ask":"22.210"},' + '"EURUSD":{"symbol":"EURUSD","lasttime":1379116796,"digits":4,"change":"-0.0001","bid":"1.3296","ask":"1.3299"}' + '}', delay: 2 }, success: function(data){ _goldAsk = parseFloat(data.GOLD.ask); _silverAsk = parseFloat(data.SILVER.ask); _eurusdAsk = parseFloat(data.EURUSD.ask); _me.trigger('stockupdated'); } }) } construct(); } window.onload = function(){ var item = new itemManager(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload