12.07.2015 Views

JSON-RPC - Custom Training Courses - Coreservlets.com

JSON-RPC - Custom Training Courses - Coreservlets.com

JSON-RPC - Custom Training Courses - Coreservlets.com

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Asynchronous <strong>RPC</strong> Calls• Idea– When calling remote function, pass JavaScript callbackfunction as the first argument to the call– The callback function should take two arguments• The real data that will <strong>com</strong>e from the server• An exception– Callback will be invoked on readyState 4.• No freezing browser until response <strong>com</strong>e in• The exception will be undefined if everything was ok• Arguments and return values– Same as in previous example. Numbers and stringspassed ddirectly. Objects have type conversion rules.• You do not escape strings. Done automatically.27Making Asynchronous Calls:Example (JavaScript)function showRandomNumber2(inputField, resultRegion) {var range = parseInt(getValue(inputField));if (isNaN(range)) {range = 1;}var callback = function(randomNumber, exception) {if(exception) {alert(exception.msg);} else {htmlInsert(resultRegion, "Number is " + randomNumber);}};rpcClient.rpcTester.getRandomNumber(callback, range);}28Note: http://jabsorb.org/Manual says to use“exception.message”. However, debugging withFirebug shows that it is “exception.msg” in thecurrent release.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!