Ajax实现xmlrpc消息的例子
<html>
<head>
<script type="text/javascript">
function sendXRPC()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myres").value=xmlhttp.responseText;
}
document.getElementById("status").innerHTML="";
}
var nodeUrl = document.getElementById("nodeip").value;
var reqStr = document.getElementById("myreq").value;
xmlhttp.open("POST",nodeUrl,true);
xmlhttp.send(reqStr);
document.getElementById("status").innerHTML="please wait...";
}
function loginExample()
{
var loginStr = "<req s="123456">\r\n\
<login u="admin" p="admin">\r\n\
</login>\r\n\
</req>";
document.getElementById("myreq").value = loginStr;
}
function getExample()
{
var str = "<req s="2019373323">\r\n\
<get id="1">\r\n\
<moid c="185">\r\n\
</moid>\r\n\
</get>\r\n\
</req>";
document.getElementById("myreq").value = str;
}
function getmExample()
{
var str = "<req s="2019373323">\r\n\
<get id="1">\r\n\
<moid c="185">\r\n\
</moid>\r\n\
</get>\r\n\
</req>";
document.getElementById("myreq").value = str;
}
function getm2Example()
{
var str = "<req s="2019373323">\r\n\
<getm2 id="1">\r\n\
<moid c="468"/>\r\n\
<filter c="468">\r\n\
</filter>\r\n\
<avlf op="and">\r\n\
</avlf>\r\n\
</getm2>\r\n\
</req>";
document.getElementById("myreq").value = str;
}
function logoutExample()
{
var str = "<req s="2019373323">\r\n\
<logout>\r\n\
</logout>\r\n\
</req>";
document.getElementById("myreq").value = str;
}
function batchGetExample()
{
var str = "<req s="520690387">\r\n\
<get id="1">\r\n\
<moid c="173">\r\n\
</moid>\r\n\
</get>\r\n\
<get id="2">\r\n\
<moid c="246">\r\n\
</moid>\r\n\
</get>\r\n\
</req>";
document.getElementById("myreq").value = str;
}
function delExample()
{
var str = "<req s="520690387">\r\n\
<del id="1">\r\n\
<moid c="181">\r\n\
<ai i="1" v="18"/>\r\n\
</moid>\r\n\
</del>\r\n\
<del id="2">\r\n\
<moid c="181">\r\n\
<ai i="1" v="9"/>\r\n\
</moid>\r\n\
</del>\r\n\
</req>";
document.getElementById("myreq").value = str;
}
function crtExample()
{
var str = "<req s="520690387">\r\n\
<crt id="1">\r\n\
<moid c="759"/>\r\n\
<avl>\r\n\
<ai i="3" v="2"/>\r\n\
<as i="2" v="desc"/>\r\n\
<as i="1" v="vfi2"/>\r\n\
<am c="205" i="4">\r\n\
<ai i="1" v="100"/>\r\n\
</am>\r\n\
</avl>\r\n\
</crt>\r\n\
</req>";
document.getElementById("myreq").value = str;
}
function setExample()
{
var str = "<req s="520690387">\r\n\
<set id="1">\r\n\
<moid c="759">\r\n\
<ai i="1" v="2"/>\r\n\
</moid>\r\n\
<avl>\r\n\
<as i="2" v="desc 2"/>\r\n\
<as i="1" v="vfi101"/>\r\n\
<am c="205" i="4">\r\n\
<ai i="1" v="102"/>\r\n\
</am>\r\n\
</avl>\r\n\
</set>\r\n\
</req>";
document.getElementById("myreq").value = str;
}
function simpleInvokeExample()
{
var str = "<req s="520690387">\r\n\
<inv id="1" o="3">\r\n\
<moid c="8">\r\n\
</moid>\r\n\
<avl>\r\n\
</avl>\r\n\
</inv>\r\n\
</req>";
document.getElementById("myreq").value = str;
}
function invokeExample()
{
var str = "<req s="520690387">\r\n\
<inv id="1" o="1">\r\n\
<moid c="349">\r\n\
</moid>\r\n\
<avl>\r\n\
<as i="1" v="name"/>\r\n\
<ai i="30" v="0"/>\r\n\
<am c="347" i="6">\r\n\
<ai i="1" v="2"/>\r\n\
<ai i="2" v="9"/>\r\n\
</am>\r\n\
<ab i="8" v="000000000003"/>\r\n\
</avl>\r\n\
</inv>\r\n\
</req>";
document.getElementById("myreq").value = str;
}
</script>
</head>
<body onload="loginExample()">
<h2>Node URL:</h2>
<input type="text" name="nodeip" id="nodeip" value="http://10.170.80.192:8080/RPC3" size="50"/>
<h2>XML-RPC Request:</h2>
<h4>Examples: Click below buttons to get the examples. </h4>
<button type="button" onclick="loginExample()">Login</button>
<button type="button" onclick="getExample()">Get</button>
<button type="button" onclick="setExample()">Set</button>
<button type="button" onclick="getmExample()">GetMany</button>
<button type="button" onclick="getm2Example()">GetMany2</button>
<button type="button" onclick="batchGetExample()">BatchGet</button>
<button type="button" onclick="delExample()">Delete</button>
<button type="button" onclick="crtExample()">Create</button>
<button type="button" onclick="simpleInvokeExample()">SimpleInvoke</button>
<button type="button" onclick="invokeExample()">Invoke</button>
<button type="button" onclick="logoutExample()">Logout</button>
<textarea name="myreq" id="myreq" rows="15" cols="100"></textarea>
<br/>
<br/>
<button type="button" onclick="sendXRPC()">Send</button>
<font color="red">(please correct the session id before sending to the node.)</font>
<hr>
<h2>XML-RPC Response: <font color="green" size="3" id="status"></font></h2>
<textarea name="myres" id="myres" rows="15" cols="100"></textarea>
<div id="mail">
Any issue, please contact with: ruijun.fan@ericsson.com
</div>
</body>
</html>