Test Get Conversion Rate API
This is just a sample snippet to test the Get conversion rate API: https://github.com/svignara/get-conversion-rate
by Suvi Vignarajah
HTML
<form name="conversionFinder">
<p>
<em>* required</em>
</p>
<label>Selling value (leave empty if you just want conversion factor):
<input type="number" name="sellValue" min="1">
</label>
<label>Selling Currency*:
<input type="text" name="sellCurrency" required>
</label>
<label>Buying Currency*:
<input type="text" name="buyCurrency" required>
</label>
<input type="submit" value="Submit">
</form>
<div id="result"></div>
<div class="notes">
<strong>Resources:</strong>
<ul>
<li>Project repo: <a href="https://github.com/svignara/get-conversion-rate">https://github.com/svignara/get-conversion-rate</a></li>
<li><a href="https://svignara.github.io/experiments/2016/05/08/get-conversion-rate/">Blog post</a></li>
</ul>
</div>
CSS
label {
display: block;
margin-bottom: 10px;
}
.notes {
font-size: smaller;
margin-top: 30px;
}
JavaScript
(function() {
'use strict';
$(function() {
$('form[name="conversionFinder"]').on('submit', function(e) {
e.preventDefault();
var sellCurrency = (this.sellValue.value) ? this.sellValue.value + '+' + this.sellCurrency.value : this.sellCurrency.value,
buyCurrency = (this.buyCurrency.value);
$.ajax({
url: 'https://get-conversion-rate-from-suvi.herokuapp.com/api/convert',
data: {
sellCurrency: sellCurrency,
buyCurrency: buyCurrency
},
success: function(data) {
var result = JSON.stringify(data, null, "\t"),
resultContainer = document.getElementById('result'),
pre = document.createElement('pre');
pre.innerHTML = result;
while (resultContainer.hasChildNodes()) {
resultContainer.removeChild(resultContainer.lastChild);
}
document.getElementById('result').appendChild(pre);
},
error: function(xhr, status, err) {
console.log(xhr, status, err);
}
});
});
});
}());