ColdFusion Proxy to avoid Cross-Site Scripting

Here’s a method to get an JSON feed with ColdFusion. This will work in ColdFusion 7 and later.

This is useful for avoiding cross-site scripting in Javascript/jQuery – You would simply call your remote feed on your local server, and then your jQuery would be able to call a “local” resource.

Code walkthrough:

  • Use CFHTTP to generate an HTTP request and handle the response from the server. This should return JSON.
  • Set the appropriate MIME content type.
  • Return the resulting JSON string.

This example should be enhanced with try/catch error handling

http://pastebin.com/embed_iframe.php?i=XTBmUHP0

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