This is a simple bridge for making cross-domain AJAX requests to a specific remote host, probably your API hosted on a different domain from your main app.
-
Add bridge.js and iframe.html to the list of files hosted by your API.
-
In the API wrapper you provide to your clients, do the following:
<script src="path/to/bridge.js"></script> <script> $(document).ready(function(){ Bridge.init("http://your-domain.com/path-to-your/iframe.html", "http://your-domain.com"); //... your stuff }); </script>
-
Whenever, in your API, you would have done $.ajax({...}), use Bridge.ajax({...}) instead.
- you are good to make POST requests across domains
- callbacks to success/error will work.
- There's a TODO in the code explaining where to ensure that you are taking care to secure yourself from cross-domain attacks. Your implementation may well differ from ours.
- test* provides a simple testing framework. You only need iframe.html and the bridge.js to be included in the things provided by your API.