Make cross-domain requests in Javascript to any domain or sub-domain
JavaScript CSS
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Request.js - Simple cross-domain requests

Request.js lets you make cross-domain requests to different domain or sub-domain for JSON data sources. For a simple demonstration, visit the demo page or download a tagged release and open demo directory.

It uses the technique for secure cross-domain browser based data transfer. It works by loading a external HTML file on the remote domain in an iframe. The HTML file makes a local XMLHttpRequest request, sets its to the string content of the response. The value of is available as a response.

This project was originally put together here so I could host JSON on a DropBox account and access it from anywhere without a proxy. It is not limited at all to just JSON.

This project does not rely on jQuery or any other framework except for an implementation of JSON.parse. It does however require a little thought to the initial setup.


To use Request.js, it's easiest to download a packaged release.

The parent directory contains these two files; request.js and bell.html

Moved these to the site in which you intend to make the cross-domain requests from.

There are two files of interest within the remote-site directory; json2-min.js and xmlhttprequest.html

Move these to the remote site in which contains JSON files you intend to access.


Here is a simple example of how to make a request. In this case it is assumed that request.js and bell.html are in the same directory as the example.

Include the following in the <head> of your document:

<script src='/path/to/request.js'></script>

And the example:

var url = ""; // Regenerated from Hacker News ( every 30 minutes

var options  = {
	callback: function(response){
		if (response.status!=200) {
	bell:    "bell.html",
	tunnel:  ""

new Request(url, options);

The value for bell must be the full relative path to website. So if the full path to the file is:

Then you should have:

	bell:    "/path/to/bell.html",
	tunnel:  ""

Instead of passing bell and tunnel each time you make a request, you can modify request.js to provide default values:

var pathBell  = "bell.html";
var uriTunnel = "";

Passing values for bell and tunnel in a request will over-ride defaults.


The heavy lifting was done by Pau Santamases a good many years ago when we both worked on a now defunct project called TimesPeople. Also, to Douglas Crockford for json-js script.

Further Reading

Cross-Domain Communication with IFrames Transport