RetroZilla/extensions/xml-rpc/test/xml-rpc.xul
2015-10-20 23:03:22 -04:00

62 lines
1.6 KiB
XML

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window title="XML-RPC test"
style="margins: 5 5 5 5"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript"><![CDATA[
function getClient() {
return Components.classes['@mozilla.org/xml-rpc/client;1']
.createInstance(Components.interfaces.nsIXmlRpcClient);
}
var xmlRpcClient;
function getXmlRpc() {
if (!xmlRpcClient) xmlRpcClient = getClient();
return xmlRpcClient;
}
function callAsync() {
dump('Call Async\n');
var xmlRpc = getXmlRpc();
xmlRpc.init('http://betty.userland.com/RPC2');
var stateCode = xmlRpc.createType(xmlRpc.INT, {});
stateCode.data = document.getElementById('statecode').value;
xmlRpc.asyncCall(Listener, null, 'examples.getStateName', [stateCode], 1);
}
var Listener = {
onResult: function(client, ctxt, result) {
result = result.QueryInterface(Components.interfaces.nsISupportsCString);
document.getElementById('statename').setAttribute('value', result.data);
},
onFault: function(client, ctxt, fault) {
dump('Fault! ' + fault + '\n');
},
onError: function(client, ctxt, status, errorMsg) {
dump('Error! <(' + status.toString(16) + ') ' + errorMsg + '>\n');
}
};
]]></script>
<vbox flex="1">
<spacer flex="1"/>
<text value="Enter a state code:"/>
<textbox id="statecode"/>
<text value="Statename:"/>
<text id="statename" value=" "/>
<spacer flex="1"/>
</vbox>
<vbox>
<spacer flex="1"/>
<button label="Call Async." onclick="callAsync()"/>
<spacer flex="1"/>
</vbox>
</window>