views:

226

answers:

2

I have a php page called 'dataFetch.php' which sits on one webserver. On another webserver, I have a JS file which issues JSON calls to dataFetch. dataFetch connects to a database, retrieves data and puts it in a JSON format which is fed back to the calling program. In IE, this works fine. In other browsers it does not because of the cross domain restriction.

To get across the cross-domain restriction, I make a call to a file, proxy.php, which then makes the call to dataFetch. My problem now is that proxy.php retrieves the file from dataFetch but the JS script file no longer sees the response from proxy.php as a JSON format and so I can't process it. Can anybody help me out?

A: 

Hi,

Try this: http://pt2.php.net/curl

yoda
A: 

Have a look at using JSONP instead, which solves the cross site difficulties you have had.

Please explain how the proxy works. A proxy should be very simple, something like this:

<?php
$url = $_GET['ur'];
echo file_get_contents($url);
?>

And used like this:

http://www.example.com/proxy.php?url=http%3A//www.someothersite.com/dataFetch.php

Marius
i used curl instead for the proxy and the call to proxy is made with getJOSN(url, function(results){ <body of function>});