Friday, September 14th, 2007
JSONRequest Extension for Firefox
Collin Jackson has written a JSONRequest extension for Firefox that exposes the JSONRequest communication API to web pages you visit.
It does this by adding a new window.JSONRequest object to your world.
An example of using this beast is on the main page itself:
-
-
function request(method, data) {
-
var timeout = document.getElementById("timeout").value;
-
var url = document.getElementById("url").value;
-
var requestNumber;
-
if (timeout != "") {
-
if (method == "get") {
-
requestNumber = JSONRequest.get(url, done, timeout);
-
} else if (method == "post") {
-
requestNumber = JSONRequest.post(url, data, done, timeout);
-
}
-
} else {
-
if (method == "get") {
-
requestNumber = JSONRequest.get(url, done);
-
} else if (method == "post") {
-
requestNumber = JSONRequest.post(url, data, done);
-
}
-
}
-
document.getElementById('results').innerHTML +=
-
"Sending request " + requestNumber + "...<br />";
-
}
-













This is great news. With CrossSafe and this, we now have a native solution as well as a pure JS partial implementation of the JSONRequest. This is a great combination, because you could use CrossSafe, and it will automatically defer to native JSONRequest (like this) when available, otherwise it will do itself.
However, Colin, it appears that it behaves a little different than I expected, the JSONRequest object is not available until after the page is finished loading, so inline scripts can’t access JSONRequest immediately. Is there any reason for this? I would like to make sure CrossSafe works properly with your extension (properly defer to the plugin when available).
I don’t get it. Why is this worth an extension when we can easily serialize and deserialize in JS already?
@Calvin
href=”http://www.json.org/JSONRequest.html
I’m following up with Kris offline to come up with a solution to the load timing issue.
Calvin, the short answer to your question is that JSONRequest lets you retrieve information across domains (unlike XMLHttpRequest) and safely (unlike the cross-domain script tag). For more information, see the JSONRequest proposal page.
Good news! I hope JSONRequest become a de facto standard ;)
Why the code is not submitted as patch for bug 360666.
Great news and great that this is getting coverage in the community… (thanks Ajaxians). … JSONRequest seems very like a very reasonable solution and straightforward to implement.
I’ve released a new version of the JSONRequest extension (version 0.5) to handle the issue that Kris brought up.
This is sad.
Doug and others agreed that JSONRequest was the wrong way to solve this problem. The right solution is to use XMLHttpRequest2 which is available in nightly builds of Firefox3.
http://www.w3.org/TR/access-control/
https://bugzilla.mozilla.org/show_bug.cgi?id=389508
I am strongly in favor of the JSONRequest. It is the right way to solve the problem. I dislike the XMLHttpRequest2 because it is confused about trust boundaries, and as we have repeatedly learned in the trenches, security is rarely obtained with confusion.