Drupal services XML-RPC access from javascript
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:
开发者_运维问答can anyone tell me what going on? I tried almost all the possible options but of no use..
POST tab:
Its working fine from the XML-RPC admin screen!
Thanks
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).
精彩评论