0

在发布新网站前不久,我们发现计算机中的同源策略限制了对同一源、源或域上的页面的访问。这是网站:http ://blanc-encens.com/ 。

更糟糕的是,如果它不能立即工作,在重新加载后它会工作!!

您能否从理论上告诉我为什么会发生这种情况,或者如果您是被选中的少数人之一,那么它在哪里不起作用检查问题?编辑:我现在手动将标题设置为“*”!

Chrome 控制台错误:

XMLHttpRequest cannot load http://blanc-encens.com/profile?ajax=1. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.blanc-encens.com' is therefore not allowed access. profile:1 0 core.js:271

在 Chrome 中Response Headers,不工作的机器上的网络选项卡中没有。

我的代码:

var hyper = {
    init : function() {
        this.content($('.navigation a').not('.follow a'));
        this.pop();
    },

    content : function(obj) {
        obj.on('click', function(e){
            var thisUrl = $(this).attr('href');
                thisalt = $(this).attr('alt');
            hyper.load(thisUrl);
            e.preventDefault;
            window.history.pushState(null, thisalt, thisUrl);
            document.title = thisalt;
        });
    },

    pop : function() {
        window.onpopstate  = function() {
            hyper.load(location.pathname);
        };

    },

    load : function(page) {
        page = page == '/' ? '/start' : page;
        $.ajax({
            type: 'GET',
            url: page, 
            data: {ajax : 1},
            success: function(data) {
            $('.content').empty().append(data);
            }
        });
    }
};
hyper.init();

谢谢!!

4

1 回答 1

0

我现在带着我认为在这种情况下的“竞争条件”回来了。Barmar 在他的第一条评论中一针见血,感谢 KevinB 这么长时间一直陪伴我并为我整理好一切。;)

中的线条.htaccess

RewriteCond %{HTTP_HOST} ^www\.blanc-encens\.com
RewriteRule (.*) http://blanc-encens.com/$1 [R=301,L]

Javascript 中的旧行

var thisUrl = 
location.host == 'blanc-encens.com' 
? '/test' + $(this).attr('href') 
: $(this).attr('href');  
  • 现在有人给出了www前面的链接,这个脚本显然没有准备好。
  • 所以比赛条件一定是已经.htaccess不工作了(有人听说过吗?),或者不够快。
  • 当有人打开页面时,它当然总是开始,但是在第一次点击一个链接时,就会出现明显的混乱。
  • .htaccess没有首先工作或不够快,然后有人点击了一个链接,Javascript 决定没有blanc-encens.com;您可以在错误消息中看到,/test在 URL 中没有。
  • 然后被.htaccess踢了进去。
  • 等等,你试图从www域切换到无www域。Bumm,同源策略错误。;)
于 2013-12-08T14:04:21.560 回答