subutux / json-rpc2php

A json-rpc 2.0 server for php and some clients for php,js,python and vala.
GNU General Public License v2.0
46 stars 26 forks source link

How to wait till jsonrpc client returns response. #11

Open gubkamatus opened 10 years ago

gubkamatus commented 10 years ago

I have JS client: In JS I have function: ----------------------Start code------------------- var codebook_onlinedb;

function getCodeBook() { jsonrpcclient = new jsonrpcphp('http://some.url/server.php', function() { jsonrpcclient.cCodeBook.getCodeBook("inout", function(jsonRpcObj) { codebook_onlinedb = $.map(jsonRpcObj.result, function(value, index) { return [value]; }); }); });

function doSomething() { console.log( 'main: ' + codebook_onlinedb); }

var x = getCodeBook(); doSomething();

____End of code____

In firebug console: http://oi61.tinypic.com/2u7m1r9.jpg In firebug console I have two POST calls. First gives me a list of methods and second gives me correct response to my task but my JS function doSomething is performed in first POST. Why? Or how can I wait to correct response from second POST. Thanks.