Hello guys! I’m using the currency converter api from rapidapi. I’ve tried to save data to my database to show in textbox but I failed. Can you suggest to me anything?
import { fetch } from 'wix-fetch';
$w.onReady(function () {
getsterlin();
geteuro();
getdolar();
$w("#dataset1").onReady(() => {
let count = $w("#dataset1").getTotalCount();
$w('#dataset1').setCurrentItemIndex(count - 1)
});
function getdolar() {
fetch("https://currency-converter5.p.rapidapi.com/currency/convert?format=json&from=USD&to=TRY&amount=1", {
"method": "GET",
"headers": {
"x-rapidapi-key": "*****",
"x-rapidapi-host": "currency-converter5.p.rapidapi.com"
}
})
.then(response => response.json())
.then(result => {
console.log(result);
console.log(result.rates.TRY.rate);
$w("#dataset1").onReady(() => {
$w("#dataset1").setFieldValues({
"title": "Dövizler",
"dolar": (result.rates.TRY.rate).slice(0, 4)
});
});
})
.catch(err => {
console.error(err);
});
let item = $w("#dataset1").getCurrentItem()
let val = item.dolar
$w("#text54").text = String(val)
}
function geteuro() {
fetch("https://currency-converter5.p.rapidapi.com/currency/convert?format=json&from=EUR&to=TRY&amount=1", {
"method": "GET",
"headers": {
"x-rapidapi-key": "****",
"x-rapidapi-host": "currency-converter5.p.rapidapi.com"
}
})
.then(response => response.json())
.then(result => {
console.log(result);
$w("#dataset1").onReady(() => {
$w("#dataset1").setFieldValues({
"title": "Dövizler",
"euro": (result.rates.TRY.rate).slice(0, 4)
})
});
})
.catch(err => {
console.error(err);
});
let item = $w("#dataset1").getCurrentItem()
let val = item.euro
$w("#text55").text = String(val)
}
function getsterlin() {
fetch("https://currency-converter5.p.rapidapi.com/currency/convert?format=json&from=GBP&to=TRY&amount=1", {
"method": "GET",
"headers": {
"x-rapidapi-key": "***",
"x-rapidapi-host": "currency-converter5.p.rapidapi.com"
}
})
.then(response => response.json())
.then(result => {
console.log(result);
$w("#dataset1").onReady(() => {
$w("#dataset1").setFieldValues({
"title": "Dövizler",
"sterlin": (result.rates.TRY.rate).slice(0, 4)
})
});
})
.catch(err => {
console.error(err);
});
let item = $w("#dataset1").getCurrentItem()
let val = item.sterlin
$w("#text107").text = String(val)
}
})