Reputation: 13679
How can I pass Json Rpc data to a specified callback function, just like Json. You can get the response data by specifying the callback parameter in the url.
For example:
var url = "http://...sample/..?alt=new&callback=dispUser";
var script = document.createElement('script');
script.src = url;
document.body.appendChild(script);
then the result would be something like this
dispUser({ "id": "" });
but in Json Rpc I can't, is there a way to get the response data of Json Rpc by declaring a callback. If none how would I display these data in a client side. Because I can only get these api services using Json Rpc or SOAP XML, that's what the documentation tells.
Upvotes: 2
Views: 2389
Reputation: 5171
Your example is in JSONP style. Here's an example in JSON-RPC style:
var mathService;
function init() {
mathService = RPC.consume('http://foo.bar/mathematics.smd', mathReady);
}
function mathReady() {
mathService.cuberoot(9, function(root) {
$('#example_output').html(root);
});
}
window.onload = init;
If the JSON-RPC service doesn't describe itself via SMD, you might write something like this instead:
function init() {
RPC.callMethod('http://foo.bar/mathematics.php', {
method: 'cuberoot',
params: [ 9 ]
}, function(error, result) {
$('#example_output').html(result);
});
}
window.onload = init;
There are quite a few libraries for doing JSON-RPC from a JavaScript client (e.g: the browser), and each may be slightly different in calling convention.
Upvotes: 2