jquery - Calling REST request and handling REST response -
rest request
post host:port/chaincode { "jsonrpc": "2.0", "method": "deploy", "params": { "type": 1, "chaincodeid":{ "path":"github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" }, "ctormsg": { "function":"init", "args":["a", "1000", "b", "2000"] } }, "id": 1 }
rest response
{ "jsonrpc": "2.0", "result": { "status": "ok", "message": "52b0d803fc395b5e34d8d4a7cd69fb6aa00099b8fabed83504ac1c5d61a425aca5b3ad3bf96643ea4fdaac132c417c37b00f88fa800de7ece387d008a76d3586" }, "id": 1 }
i have set of request , response, , mention interface port 5000. how call rest request , alert response result? tried jquery couldn't it. kept prompting me window error.
this i've tried doing
$.post('localhost:5000/chaincode', { "jsonrpc": "2.0", "method": "deploy", "params": { "type": 1, "chaincodeid": { "path": "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" }, "ctormsg": { "function": "init", "args": ["a", "1000", "b", "2000"] } }, "id": 1 }, function (serverresponse) { alert(serverresponse); //do want server response })
your code looks quite good.
the possible problem see in sending request service might not run on localhost.
the result - per specification - object. since alert()
print [object]
, better use console.log()
debug output.
Comments
Post a Comment