如何使用javascript将服务器数据提供给webflow站点



我已经成功地使用我的节点服务器接收API数据,现在我想在我的webflow网站上显示它。我可以很容易地做到这一点与本地index.html客户端,但如何做到这一点,当它是一个远程客户端托管在webflow?我需要在webflow代码块中添加什么客户端javascript来显示控制台记录的数据?这是我的node js代码。谢谢你的帮助。

const Blockfrost = require('@blockfrost/blockfrost-js');
const API = new Blockfrost.BlockFrostAPI({
projectId: 'xxxxxxxxxxxxxxxxx',
});
const PAGE_SIZE = 100 /* 100 is the max Blockfrost page size */
const stake_address = 'stake1';
async function count_assets() {
let total = 0;
try {
let page = 1;
let assets = [];
// Retrieve assets as long as pages are full
do {
assets = await API.accountsAddressesAssets(
stake_address,
{ page: page, count: PAGE_SIZE, order: 'asc' }
);
total += assets.length;
page++;
} while (assets.length == PAGE_SIZE);
} catch (err) {
console.log('error', err);
}
return total;
}
count_assets(stake_address).then(assets => {
console.log(stake_address, 'assets:', assets);
});

你可以使用JQuery从webflow上的node.js应用程序中获取数据。在页面的before标签中编写代码:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$.ajax({
type: "GET",
url: "https://dummyjson.com/products/1",
dataType: "json",
success: function(data) {
$(".div-block").append(
"<p>" + data.title + " - " + data.price + "</p>"
);
},
error: function(error) {
console.log("An error occurred: " + error);
}
});
});

你可以在https://www.w3schools.com/jquery/jquery_ajax_get_post.asp上找到更多关于如何从/到你的node.js应用程序获取()或post()数据的文档

最新更新