AJAX cross-domain request using iframes

I had a situation where I had to send a form to a 3rd party email subscription management thingy. But every time I posted the form using jQuery the browser was killing it because of cross-domain restrictions. I asked around the web dev team and came up with this solution. Simply create a URL fragment from the form inputs, and use it as the source of an iframe. Of course, as long as you don’t care what happens to the data this is fine – it’s basically best-effort.

Caveats are that if the domain the client is on is HTTPS the URL fragment also has to be HTTPS but if the destination server doesn’t have a valid SSL certificate the submission fails. It fails silently in Chrome, Firefox and IE7. Sometimes it triggers a message in IE8 but it definitely triggers a security pop-up in IE6 (of course).

I found that Google chrome is the best browser for developing this because it actually tells you what is going on in the console and in the iframe – the rest just act like nothing happened.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s