官术网_书友最值得收藏!

  • 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.

主站蜘蛛池模板: 扶风县| 磐石市| 佛坪县| 营山县| 廊坊市| 益阳市| 富川| 巴彦县| 安达市| 同仁县| 资源县| 灯塔市| 合阳县| 宁远县| 河北区| 广东省| 城市| 广宁县| 湟中县| 奉贤区| 长寿区| 绥棱县| 文昌市| 辛集市| 庆安县| 乌兰浩特市| 南漳县| 左权县| 北流市| 绥德县| 泾川县| 罗城| 崇礼县| 陈巴尔虎旗| 辉县市| 嘉峪关市| 五原县| 沈阳市| 安新县| 博野县| 崇州市|