- Hyperledger Cookbook
- Xun (Brian) Wu Chuanfeng Zhang Andrew Zhang
- 193字
- 2021-06-24 14:59:43
Writing Node.js client-side code
We still need to work on one more file before we complete the end-to-end development. The Node.js client-side code provides a user interface, lets the user see the blockchain result in the browser, and invokes a method from a web page. Our Node.js client-side code can be found in index.ejs under the views folder. We can open this file and start to add some code in it.
For the Ship function, we use the jQuery post method to call the Node.js server-side Ship function. This will invoke the blockchain Ship method in the assetmgr chaincode, as follows:
<script>
$(document).ready(function(){
$("#ship").click(function(){
$.post("http://52.15.203.98:3000/ship", function(data){
var parsedJson = $.parseJSON($.parseJSON(data));
console.log(parsedJson);
});
});
});
</script>
The query function is similar to the Ship code; we use the jQuery get method to call the Node.js server-side query function, which will invoke the blockchain query method in the assetmgr chaincode.
Once the results return, it populates the data to the related fields on the UI:
$("#chainCodeQuery").click(function(){
$.get("http://52.15.203.98:3000/query",
function(data){
var parsedJson = $.parseJSON($.parseJSON(data));
$("#assetType").val(parsedJson.assetType);
…
});
});
We have now completed our end-to-end code. It is time to start our node server and do some quick experiments.
- Hands-On Blockchain Development in 7 Days
- 數(shù)學(xué)女孩2:費馬大定理
- 我的第一本趣味數(shù)學(xué)書2
- 數(shù)獨游戲全集
- 數(shù)學(xué)原來可以這樣學(xué):初中篇
- Mastering Ethereum
- 排序問題的數(shù)學(xué)規(guī)劃松弛方法
- 丈量世界:時間、空間與數(shù)學(xué)(萬物皆數(shù)學(xué))
- 特殊函數(shù)概論習題解答
- ANSYS Workbench 2020有限元分析從入門到精通(升級版)
- 燒腦的邏輯題
- 你沒想到的數(shù)學(xué)
- 線性代數(shù)
- 第四屆(2018)北京高校數(shù)學(xué)微課程教學(xué)設(shè)計競賽優(yōu)秀作品與教改論文集錦
- 數(shù)學(xué)故事總動員