本文介绍了“Access-Control-Allow-Origin”不允许使用“jquery和random.org”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用jQuery从random.org请求随机数时遇到问题。当我使用静态页面和以下javascript时,我没有任何问题得到随机数。但是,我正在Heroku上托管一个Sinatra应用程序(同样,当使用Thin在本地生产我的应用程序时)我得到(Access-Control-Allow-Origin不允许(网站)。

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');
    });
});

};

想法?

推荐答案

老实说,我不知道你怎么能以任何方式做到这一点。因为你不应该这样做。 Access-Control-Allow-Origin是一种XSS保护,可以阻止跨域请求,是大多数客户端脚本引擎(例如Flash)的一部分。使用以下代码生成随机数:

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:

Math.random()

这篇关于“Access-Control-Allow-Origin”不允许使用“jquery和random.org”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 22:35