An implementation of XMLRPC, following the specs on "http://www.xmlrpc.com/spec". Tested using the XML_RPC2 class in PHPs PEAR and "XML-RPC for PHP" (http://phpxmlrpc.sourceforge.net/).
Usage is similar to MooTools' Request class (it has events for onSuccess and onRequest).
var rpc = new XMLRPC.call({ url: 'http://someurl/somescript.php', // will not add an empty params tag to the method call addEmptyParams: false });
You could also customize the request further (in this example it can be accessed as rpc.Request).
To send the request, use the method send(). It's first parameter is the name of the remote method to call. The second parameter can be empty (for remote methods that don't expect any parameters) or an Array of datatypes representing each parameter of the method containing the data to parse and send as XML.
rpc.send('TestClass.test', [ new Hash({ integer: 22, bool: true, double: (23).setTag('double') }), false ]);
For each call to send with a method the XML is stored so you can later use send() without parameters to resend the request, the default link-behaviour for the Request is 'chain'.
Most parameters set options of the Request-object.
onSuccess / onFailure, see: http://mootools.net/docs/core/Request/Request
window.addEvent('domready', function() { var rpc = new XMLRPC.call({ url: '/mootools-xmlrpc/server.php', onSuccess: function(response, responseText) { var debug = response.debug(); if (Browser.Engine.gecko && typeof console == 'object') { console.log(response); } try { if (Browser.Engine.trident) { var newline = '<br>\n'; debug = debug.toString().replace(/\n/g, '<br>'); } else { var newline = '\n'; } $('response').set('html', debug + newline + newline + XMLRPC.encode(responseText.replace(/>/g, '>')) ); } catch (err) { $('response').set('html', 'error: setting debug-output\n'+err); } }, onFailure: function(xhr) { if (Browser.Engine.gecko && typeof console == 'object') { console.log(xhr); } } }).send('TestClass.test', [ new Hash({ integer: 22, bool: true, string: '<Vienna & al >', date: new Date(2009, 12, 20, 15, 16, 00).setTimezone('Z') }), // try setting this to false true ]); });
A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.
Found a bug in this plugin? Please report it this repository's Github Issues.
blog comments powered by Disqus