2
我从货币层获得免费会员资格。我想转换货币,但不允许免费会员。相反,他们给了我一个LIVE API
我可以得到当前的汇率。因此,我决定通过对jQuery代码进行一些tic tac来设法使用此实时API进行货币转换。我在某种程度上修改了代码,我想我几乎成功了(也许我错了)。我对jQuery的工作知识有限,所以我被困在最后一点。以下是对问题进行解释的代码。从他们货币层API
// set endpoint and your access key
endpoint = 'live'
access_key = 'YOUR_ACCESS_KEY'; // can't reveal API key
// get the most recent exchange rates via the "live" endpoint:
$.ajax({
url: 'http://apilayer.net/api/' + endpoint + '?access_key=' + access_key,
dataType: 'jsonp',
success: function(json) {
// exchange rata data is stored in json.quotes
alert(json.quotes.USDGBP);
// source currency is stored in json.source
alert(json.source);
// timestamp can be accessed in json.timestamp
alert(json.timestamp);
}
});
收到
API我试图
上面使用// set endpoint and your access key
endpoint = 'live'
access_key = 'YOUR_ACCESS_KEY'; // can't reveal API key
var from = $('#from').val();
var to = $('#to').val();
var combine = from+to;
// get the most recent exchange rates via the "live" endpoint:
$.ajax({
url: 'http://apilayer.net/api/' + endpoint + '?access_key=' + access_key,
dataType: 'jsonp',
success: function(json) {
// exchange rata data is stored in json.quotes
//var response = json.quotes.combine;
alert(json.quotes.combine); // HERE IN PLACE OF USDGBP I USED THE COMBINE VARIABLE
$('#convert').html('response');
}
});
combine
变量返回undefined。也许我没有正确编码,因为我的jQuery知识有限。如果我能解决这个问题,那么我将能够最有可能地使用代码。请帮帮我。
正在工作...和'#convert'是一个表单字段,这里是ID转换。我需要把这个结果放在这个表单域中。假设我使用了'var response = json.quotes [combine];'。现在如何输出表单字段?我上面的代码似乎是不正确的。 –
如果'#convert'元素是一个输入,您应该使用'val()'来设置该值,例如:'$('#convert')。val(response);'。我已经为你更新了答案。 –
得到它完美的工作,因为我想..但我想知道是否有一种方法来绕过免费会员的1000 API请求限制.. –