1

I am trying to make XMLRPC connection between Server (C code) and Client (In Javascript). Client sends two numbers and server adds them and returns back. Server(in C code) is supposed to get data in the following XML form:

<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
<methodName>sample.add</methodName>
<params>
<param><value><i4>a</i4></value></param> // a and b are numbers to be added
<param><value><i4>b</i4></value></param> // a and b are numbers to be added
</params>
</methodCall>

I used mimic library for JS. So here is the client side script:

<title>Mimic - JavaScript XML-RPC Client</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<script src="mimic/mimic.js"language="javascript"></script>
....
<center>
<input type="text" id="n1"/>
<input type="text" id="n2"/>    
<input type="button"  onclick="Add_Request();" value="Request"/>
...
<script language="javascript">
          function Add_Request() {
           var method = "sample.add";
           var request = new XmlRpcRequest("demos/calc.php", method);
           request.addParam(document.getElementById("n1"));
           request.addParam(document.getElementById("n2"));
           var response = request.send();
           alert(response.parseXML());
        }
</script>

But client does not work. Where did I make mistake or...? In which form does Javascript send XML data to the server? any advice would be appreciated

Thanks in advance!!!

P.S. Implementation of XMLRPC Client and Server in C code work fine.

1 Answers1

0

You are not passing the correct url to the XmlRpcRequest function. You need to reference the mimic-sourceforge address. (This is assuming you are not running your own XML-RPC Server and just trying out this code)
...

    <script language="javascript">
          function Add_Request() {
           var method = "sample.add";
           var request = new XmlRpcRequest("http://mimic-xmlrpc.sourceforge.net/demos/calc.php", method);
           request.addParam(document.getElementById("n1"));
           request.addParam(document.getElementById("n2"));
           var response = request.send();
           alert(response.parseXML());
        }
</script>

...
If you are running this on chrome from localhost, you will eventually get a CORS issue. Follow this thread for help with that: Response to preflight request doesn't pass access control check

Community
  • 1
  • 1
Jithen
  • 1