JSON Problem with Cross Domain..Alternative Parse out of iframe?
I am taking a stab in the dark here.
I cannot do a cross domain request to get a piece of json data. I have tried this several ways but the cross domain policy keeps getting me. Is there a way I can do this by just parsing the data inside a hidden iframe? Is this possible using javascript?
http://www.nfl.com/liv开发者_开发知识库eupdate/scorestrip/ss.json is the json page
Whenever crossdomain policy puts me up against the fence, I use a PHP
proxy.
Use PHP
to curl in the file you want and then it's as good as yours. When you hit the PHP
file (which is on your server) there's no cross domain issues.
Your PHP file will look like something like this. Now whenever you hit the PHP
file, you'll see the file you curled, but it appears to be coming from your domain.
This is basically a cheap trick and should only be used when you have no control over the policies.
Here's the PHP code you will need:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://nfl.com/liveupdate/scorestrip/ss.json');
curl_exec($ch);
curl_close($ch);
?>
精彩评论