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?
Honestly I don’t get how you could do that in any way. Because you shouldn’t be able to do it. Access-Control-Allow-Origin is an XSS protection which blocks cross domain requests and is part of most client side scripting engines (e.g. Flash). Use the following to random number generation: