Creative ways to solve common problems – II

The Problem: The Javascript XHttpRequests (aka AJAX) has cross domain restrictions that keeps you from making POST requests to a different domain from the one running your client code.

The Solution: One of the most used ones is to create an iFrame with the POST data and add it to the document and submit it. But you’ll get no response back from it (like a success or failure message).

The Creative Solution: I came across this one in here and basically it relies on the fact that images are not subject to cross domain restrictions, so basically you’ll load an “image” from the server that will return a different sized image per possible result. So maybe you’ll have the possible results as SUCCESS and FAILED. You’ll just have to return let’s say a 1px image for SUCESS and a 2px image for FAILED. Then you’ll just have to check the size of the image to “read” the return message.