I just wanted to inform you about the easyXDM library(http://
easyxdm.net), a library that enables cross-domain RPC between two
between two loaded HTML documents. The library uses a protocol almost
identical to JSON-PRC, and will shortly be brought more in line with
the spec.
You can take a look at
http://easyxdm.net/wp/2010/03/17/remote-procedure-calls-rpc/
to read more about using the easyXDM.Rpc class, or you could skip
right to one of the demos
http://easyxdm.net/current/example/methods.html.
The underlying transport supports the use of several different stacks,
FIM (Fragment Identifier Messaging),
window.name and postMessage.
All transports are reliable (even the FIM), supports queuing and
fragmenting, and enforces sender-verification.
One of the current demos, showing cross-domain XHR (http://
consumer.easyxdm.net/example/xhr.html) displays the use of the generic
XMLHttpRequest RPC interface, that enables cross-domain ajax, and one
of the ideas I have is to extend this so that it can talk to a generic
JSON-RPC server using HTTP.
The end result would be to be able to expose a JSON-RPC-over-HTTP-
enabled server with very little code.
Does anyone have any suggestions for this, or wish to contribute? The
code that would need extending, or that would be best used as a base
is the current xhr.html document,
http://github.com/oyvindkinsey/easyXDM/blob/master/src/xhr.html
.
To show you an example for how the xhr sample is used:
//the following is the code needed to expose an interface usable for
AJAX
var new easyXDM.Rpc({
local: "name.html"
}, {
local: {
post: {
isAsync: true,
method: function(url, data, fn){
// You really should add some filtering to only allow
certain url's
var xhrObj = createXMLHTTPObject();
xhrObj.onreadystatechange = function(){
if (xhrObj.readyState === 4 && xhrObj.status ===
200) {
fn(JSON.parse(xhrObj.responseText));
}
};
xhrObj.open('POST', url, true);
xhrObj.setRequestHeader('Content-Type', 'application/x-
www-form-urlencoded');
var encodedData =
easyXDM.Url.appendQueryParameters("", data).substring(1);
xhrObj.send(encodedData);
}
}
}
});
//and here is the code needed to 'connect' with this from a different
domain
var xhr = new easyXDM.Rpc({
local: "../name.html",
remote: remoteUrl + "/../xhr.html",
remoteHelper: remoteUrl + "/../name.html";
}, {
remote: {
post: {}
}
});
//to make a request you use the following code
xhr.post("example/glossary.php", {
param1: "",
param2: "";
}, function(json){
alert(json.glossary.title);
});
pretty much like any standard ajax function, only that it is cross-
domain!
--
You received this message because you are subscribed to the Google Groups "JSON-RPC" group.
To post to this group, send email to
json...@googlegroups.com.
To unsubscribe from this group, send email to
json-rpc+u...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/json-rpc?hl=en.