gecko-dev/extensions/xml-rpc/test/xml-rpc.xul

61 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 language="javascript"><![CDATA[
function getClient() {
return Components.classes['mozilla.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);
}
var Listener = {
onResult: function(client, ctxt, result) {
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>
<box orient="vertical" flex="1">
<spring flex="1"/>
<text value="Enter a state code:"/>
<textfield id="statecode"/>
<text value="Statename:"/>
<text id="statename" value=" "/>
<spring flex="1"/>
</box>
<box orient="vertical">
<spring flex="1"/>
<button value="Call Async." onclick="callAsync()"/>
<spring flex="1"/>
</box>
</window>