pjs/extensions/xml-rpc/test/xml-rpc.xul

76 строки
2.2 KiB
Plaintext
Исходник Обычный вид История

<?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.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);
}
// Broken still. :(
function callSync() {
dump('Call Sync\n');
var xmlRpc = getXmlRpc();
xmlRpc.init('http://betty.userland.com/RPC2');
var stateCode = xmlRpc.createType(xmlRpc.INT, {});
stateCode.data = document.getElementById('statecode').value;
result = xmlRpc.call('examples.getStateName', [stateCode], 1);
result = result.QueryInterface(Components.interfaces.nsISupportsString);
document.getElementById('statename').setAttribute('value', result.data);
}
var Listener = {
onResult: function(client, ctxt, result) {
result = result.QueryInterface(Components.interfaces.nsISupportsString);
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:"/>
<textbox 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()"/>
<button value="Call Sync." onclick="callSync()"/>
<spring flex="1"/>
</box>
</window>