现在它可以工作了......但是我怎样才能为 json 编写正确的调用?
我尝试使用此直接链接但不起作用,也许我必须编辑“数据”参数?我不知道,因为我读到的是可选参数,对吗?有什么帮助吗?
并且我可以设置我想要选择的 json 值的连续引用,以使它们始终更新(每 60 秒)。
谢谢!!
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&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();
}