Bitcoin Forum
December 18, 2017, 08:07:50 AM *
News: Latest stable version of Bitcoin Core: 0.15.1  [Torrent].
   Home   Help Search Donate Login Register  
Pages: [1]
Author Topic: Javascript problem with Cryptoxchange API (cross-domain request) - RESOLVED.  (Read 4692 times)
Full Member
Offline Offline

Activity: 171

Crypterium - Digital Mobile Cryptobank For Everyon

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!

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!