trotter / central-dispatch
- Source
- Commits
- Network (0)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Tree:
ac3f355
commit ac3f355d6b7f784bcb7f4dee530156ada8fc34bd
tree c461e9358724b62fb46e3bff76cf0ce3fa2832eb
parent 6862c4fdd00e61896d7d1294b7d2df65af38c541
tree c461e9358724b62fb46e3bff76cf0ce3fa2832eb
parent 6862c4fdd00e61896d7d1294b7d2df65af38c541
| name | age | message | |
|---|---|---|---|
| |
MIT-LICENSE.txt | ||
| |
README.textile | ||
| |
js/ |
README.textile
CentralDispatch
CentralDispatch is a totally awesome replacement for JSONP. It pushes the
callback matching work to the client, but allows for server side caching of JSON
data. This is a huge benefit if you’re aggressively caching your application.
Client Side Usage
CentralDispatch.requestData(url, callback, options)
Parameters
| param | expected type | description |
| url | String | The url from which you’re fetching data |
| callback | Function or Hash | A function that will be called when the data is received, or a hash described below |
Options Hash:
| key | expected type | description |
| onSuccess | Function | A function to be called when the data is received |
| onError | Function | A function to be called if there is an error fetching the data |
Example
var callback = function (data) {
alert(data);
};
CentralDispatch.requestData('http://trottercashion.com/examples/cdData.js', callback)
var errorCallback = function (msg, url, line) {
alert("error: " + msg);
}
Server Side Usage
On the server, all JSON data must be wrapped in CentralDispatch.receiveData,
which is described below.
CentralDispatch.receiveData(version, url, data)
Parameters
| param | expected type | description |
| version | String | The version of CentralDispatch.receiveData you’re using, currently only v1 |
| url | String | The url where the data resides, can be a path fragment |
| data | JSON | The JSON data |
Examples
CentralDispatch.receiveData('v1', 'http://trottercashion.com/examples/cdData.js', {foo: bar});
CentralDispatch.receiveData('v1', 'examples/cdData.js', {foo: 'bar'});

