Skip to content

Solves the 'cross-domain AJAX post' similar to how Facebook does it

License

Notifications You must be signed in to change notification settings

dget/ajax_iframe_bridge

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ajax iframe Bridge

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.

Here's how you use it:

  1. Add bridge.js and iframe.html to the list of files hosted by your API.

  2. 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("https://your-domain.com/path-to-your/iframe.html",
                        "https://your-domain.com");
            //... your stuff
          });
        </script>
    
  3. Whenever, in your API, you would have done $.ajax({...}), use Bridge.ajax({...}) instead.

What's awesome about this:

  • you are good to make POST requests across domains
  • callbacks to success/error will work.

Notes:

  • 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.

About

Solves the 'cross-domain AJAX post' similar to how Facebook does it

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%