how to use proxy with JSON

两盒软妹~` 提交于 2019-12-13 03:59:44

问题


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?


回答1:


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://www.someothersite.com/dataFetch.php



来源:https://stackoverflow.com/questions/1482786/how-to-use-proxy-with-json

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!