0

I'm trying to successfully get a callback but i keep running into an error that states "XMLHttpRequest cannot load http://api.bitcoincharts.com/v1/markets.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access." this is my javascript.

$(document).ready(function(){
$(".btn").on("click", function(){
  var userDate = $("#userDate").val();
  var bitcoinApiUrl = "http://api.bitcoincharts.com/v1/markets.json";
  var bitcoinApiParams = {
    method:"currency"
  }
  // bitcoinApiUrl += "&currency" + userDate;
  $.ajax({
    type: "GET",
    AccessControlAllowCredentials: true,
    // AccessControlAllowOrigin:
    url: bitcoinApiUrl,
    success: function(response) {
    }
  });

  });
});
Villainy
  • 125
  • 7
  • Is the error message unclear, or what is your question? – Felix Kling Jan 03 '16 at 04:47
  • you are getting CORS problem, error says it all, your host server needs to send `Access-Control-Allow-Origin` header with allowed hosts that you can make request to – Bek Jan 03 '16 at 04:49
  • I'm asking how to fix it , from what i looked at i need to setup a server but is that the only way ? @FelixKling – Villainy Jan 03 '16 at 04:56
  • yes, you need to setup a server - and be sure to cache the result so you **Don't query more often than once every 15 minutes!** – Jaromanda X Jan 03 '16 at 05:02
  • If you can deal with JSON in return, then try using JSONP (note the P at the end) for speaking between domains [see this](http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource) – Rudra Jan 03 '16 at 05:51

0 Answers0