Best practices for getting cross-site JSON responses to POST? Best practices for getting cross-site JSON responses to POST? json json

Best practices for getting cross-site JSON responses to POST?


You could write a simple reflector at the server side. Add a script to each domain that simply passes your ajax request on to the appropriate domain. This script can be very simple (1 or 2 lines of code), avoids your cross site scripting issues and means you don't need to duplicate the complicated business logic in your existing scripts.

It will cause extra work for your server, but that may not be a problem for you.

The closest example code I can find on the sites I manage is the following. Here we needed to be able to use Googles Chart API on an HTTPS connection (which it does not support yet). The solution was to add the following script that passed the calls on...

<?php// Set header so our output looks like a PNGheader("Content-Type: image/png");// Reflect the image from googles chart APIecho file_get_contents('http://chart.apis.google.com/chart?'.$_SERVER['QUERY_STRING']);?>


just look at this https://developer.mozilla.org/En/HTTP_access_control page. All what you need - add header to all you scripts that accept post request. Example:


I use REST approach in such cases.Search google for more information about REST.