簡體   English   中英

由於bingbots,ActionController :: InvalidCrossOriginRequest異常

[英]ActionController::InvalidCrossOriginRequest exception due to bingbots

我有Rails應用程序,我在頁面加載后使用Ajax加載評論。

class CommentsController < ApplicationController
  respond_to :js

  def index
    @comments = Comments.all
    respond_with @comments
  end
end

它按預期工作。 但是bingbot試圖訪問它導致的網址

在comment#index中發生了一個ActionController :: InvalidCrossOriginRequest: 安全警告:另一個站點上的嵌入式標記請求受保護的JavaScript。 如果您知道自己在做什么,請繼續對此操作禁用偽造保護,以允許跨域JavaScript嵌入。

像這樣,所有僅響應js格式的網址都將出現。

我知道關於rack-cors ,但是它是允許跨腳本訪問的,但是這里不是。

app / views / comments / index.js.erb

$('.comments_container').html("<%=j render 'comments' %>");

comments.js

jQuery(function() {
  return $.ajax({
    url: $('.comments_container').data('url')({
      dataType: "script"
    })
  });
});

假設您需要一些有關CORS(跨域資源共享)的幫助,您會遇到錯誤,因為您的CORS策略默認為“拒絕”每個XHR直接訪問。

您可以使用rack-cors gem https://github.com/cyu/rack-cors避免這種情況。 希望對您有所幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM