与服务器呈现的html表单的phonegap产生null引用错误

问题描述 投票:1回答:1

我有一个基本的phonegap应用程序,只有默认的index.html,一旦index.html被加载并且device_ready事件触发,我直接从服务器使用ajax加载html表单并仅替换index.html的主体。到目前为止一切都很好..但是当提交表单回到rails服务器时,我得到以下错误

ActionController::InvalidAuthenticityToken (The browser returned a 'null' origin for a request with origin-based forgery protection turned on. This usually
means you have the 'no-referrer' Referrer-Policy header enabled, or that you the request came from a site that
refused to give its origin. This makes it impossible for Rails to verify the source of the requests. Likely the
best solution is to change your referrer policy to something less strict like same-origin or strict-same-origin.
If you cannot change the referrer policy, you can disable origin checking with the
Rails.application.config.action_controller.forgery_protection_origin_check setting.
):

我试过在index.html中设置referrer

    <meta name="referrer" content="unsafe-url" /> or
    <meta name="referrer" content="origin-when-crossorigin" />

产生

HTTP Origin header (file://) didn't match request.base_url (http://192.168.1.5:4000)

仍然得到同样的错误。

一些额外的信息:index.html协议是file:/// server_side.html,http://协议是XHR加载到index.html

ruby-on-rails html5 cordova phonegap w3c
1个回答
0
投票

我知道回答这个问题为时已晚,你可能已经解决了。

无论如何,为了我的特殊目的,我通过在我的Rails应用程序中向config/application.rb添加以下行来解决类似的问题:

Rails.application.config.action_controller.forgery_protection_origin_check = false
© www.soinside.com 2019 - 2024. All rights reserved.