1

I am trying to access the XML-RPC of my local drupal installation, from javascript. Here is the code:

$.ajax({
            type: "POST",
    url: "http://www.sms2.com/services/xmlrpc",
    dataType: "xml",
    data: {"method": "node.get",
                "nid": 1
            },
    success: function(msg) {
        //alert("data: " + msg.type );  
                    console.log("amrit");
    }
});

My drupal index file is in /home/dark/web_root/sms2/index.php and HTML file is in /home/dark/web_root/sms2/test.html

'sms2' is set from /etc/hosts file.

This is the response I am getting:

enter image description here

can anyone tell me what going on? I tried almost all the possible options but of no use..

POST tab: enter image description here

Its working fine from the XML-RPC admin screen! enter image description here

Thanks

Amrit
  • 1,964
  • 19
  • 25
  • Show us also the Post tab - what data are you sending in? From the `faultString` I guess that data came in the format that XML-RPC does not distinguish... Can You provide also some code from XML-RPC procedire where loading of POST data is visible? – shadyyx May 04 '11 at 16:02
  • OK, the problem with `.post()` method is that it does exactly what it is called - it posts the data to a given URL... This means that at given URL there must be a script that listens to POST data, grabs the `$_POST['method']` and `$_POST['nid']` and does something like this: `$method = $_POST['method']; $nid = $_POST['nid']; return $method($nid);` or `echo $method($nid);`. What does the script here http://www.sms2.com/services/xmlrpc looks like??? – shadyyx May 04 '11 at 16:18
  • mmmm... I have no idea :( It comes with drupal module (http://drupal.org/project/services) I am referring the above code from http://groups.drupal.org/node/78093 – Amrit May 04 '11 at 16:23
  • Hmm, if it is Drupal oriented XML-RPC maybe then trying the Drupal Forums would be better first... What I've found is calling it from PHP - so You can call Your own PHP script with Your AJAX call that will then call the XML-RPC. Here is the link: http://drupal.org/node/836116 – shadyyx May 04 '11 at 16:29

1 Answers1

1

As shown in the screenshot of your POST tab, You are not POSTing data in the format expected for an XML-RPC call. So when the Services's XML-RPC handler try to read your data, it fails with the returned error.

The same error is discussed at http://groups.drupal.org/node/6823#comment-478604 with possible solution.

If you only build JavaScript client, you don't need to use the XML-RPC backend for Services. Services 3.x (beta) provides a REST backend supporting both XML and JSON. For earlier releases one of the JSON, JSON-RPC and REST backend should be easier to work with.

Off course, you can also use an XML-RPC JavaScript library (compatible with jQuery).

Community
  • 1
  • 1
Pierre Buyle
  • 4,883
  • 2
  • 32
  • 31
  • Thanks. Its XML-RPC stuff if working with [link](http://code.google.com/p/json-xml-rpc/). But I want to use JSON-RPC and implement cross-domain calls. Can you help me with this? [link](http://code.google.com/p/json-xml-rpc/) is having JSON, but its not using the POST method... – Amrit May 06 '11 at 04:19