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

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.

主站蜘蛛池模板: 射阳县| 廊坊市| 天镇县| 手机| 奈曼旗| 绥中县| 资溪县| 鸡东县| 大荔县| 茂名市| 阿拉善盟| 绩溪县| 乐至县| 盐山县| 大厂| 客服| 城口县| 大丰市| 高雄县| 岑巩县| 平江县| 土默特左旗| 同仁县| 湟中县| 乌海市| 秭归县| 林州市| 武强县| 兴宁市| 尉犁县| 佳木斯市| 繁昌县| 南平市| 河间市| 紫阳县| 股票| 沙田区| 余江县| 吉隆县| 青冈县| 莱阳市|