Problem this snippet solves: Pretty self-explanatory - we had to implement CORS (Cross-Origin-Resource-Sharing) where we had multiple domains, all of which had to be able to make AJAX calls to API's...
You should create a data group called "allowed_origins" type string and add the list of your domains to it. You can then make a call to this data group from an iRule.