Bitcoin Forum
May 21, 2018, 12:06:41 PM *
News: Latest stable version of Bitcoin Core: 0.16.0  [Torrent]. (New!)
   Home   Help Search Donate Login Register  
Pages: [1]
Author Topic: Javascript problem with Cryptoxchange API (cross-domain request) - RESOLVED.  (Read 4693 times)
Full Member
Offline Offline

Activity: 169
Merit: 100

Deal Coin - P2P Lending Eco-system

View Profile
March 05, 2012, 03:45:34 AM

I am trying to use some simple javascript to poll the ticker at


$.getJSON("", function(data) {

Now, the response that I get is:

XMLHttpRequest cannot load Origin is not allowed by Access-Control-Allow-Origin.


This problem is related to an issue with Javascript and cross-domain security.  You can't make cross-server http requests with Javascript as this is blocked 99% of the time.  

The solution to this problem is simple.

Create "proxy.php" that contains the following:

$url = '';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
echo json_encode($output);

So what happens is obvious.  You go to and you get the JSON response from the php script.

Now in your main html file, you just use as the address for the Javascript HTTP request.

$.getJSON("proxy.php", function(data) {

Its that simple!

The Deal Coin      BLOCKCHAIN LENDING PLATFORM                   
FACEBOOK     PRE-SALE | March 26th  ]     TWITTER     [ CROWDSALE | April 16th ]     TELEGRAM
ANN THREAD          ⚫          BOUNTY THREAD          ⚫          WHITEPAPER
Pages: [1]
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!