I am having a problem requesting a random number from random.org using jQuery. When I'm using a static page and the following javascript, I don't have any issues getting random numbers. However, I am hosting a Sinatra app on Heroku (also, when running my app locally in production using Thin) I get "(website) is not allowed by Access-Control-Allow-Origin."
function raffler(){
var rowCount = $('#winnerTable tr').length;
$('#winnerButton').click(function() {
$.get("http://www.random.org/integers/?", {num: "1", min: "1", max: rowCount, col: "1", base: "10", format: "plain", rnd: "new"}, function(randNum) {
var myNumber = randNum;
$("#entry-" + randNum).addClass('winner');
});
});
};
Thoughts?
Well, on a quick check, random.org doesn't return any CORS headers. This explains, why you are not allowed to request it via Javascript from your website.
Hav you loaded your static file, where it works, locally, i.e., via file:///
protocol? There are other security measurements on duty, and browsers usually allow cross-domain AJAX.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With