rails SweetAlert 2 在 ie11 中不工作

rails SweetAlert 2 not working in ie11

在我的 rails 应用程序中,当用户点击一个按钮时,浏览器发送一个 js post 请求,控制器计算一些东西,然后 returns 一个 js SweetAlert2 (swal) 到浏览器。

它在 chrome、firefox 和 safari 上运行良好。但是在ie11上,点击按钮什么也没有发生!知道为什么吗?

这是视图中发送 js post 请求的 submit_tag 按钮。

<%= form_tag('check_exemption', remote: true) do %>
  # Here are some radio buttons that are used to pass parameters to the controller. 

  <p><%= submit_tag('Check Exemption', class: 'btn btn-danger btn-block btn-xl') %></p>
<% end %>

这是路线:

post ':action', to: 'protected_assets#check_exemption'

这是 protected_assets_controller 中的操作:

def check_exemption
  # Here the controller calculates some stuff to be returned in the swal below.

  respond_to do |format|
    format.html { redirect_to root_url }
    format.js { render js: "swal('#{@financial_product.product_exemption_text}', '#{@financial_product.twelve_months_exempt_text} #{@financial_product.withdrawals_exemption_text}', '#{@financial_product.swal_type}')" }
  end
end

这是 ie11 检查面板,我们在其中看到 swal 已正确返回。然而,swal 并没有显示在屏幕上!请注意,如果请求是 html 请求而不是 js:

,页面也不会像应该的那样重定向到 root_url

ie 11 panel

我是 rails、Web 开发、javascript、html、css 等新手。所以请像您一样写下您的答案与 child 或聪明的狗交谈。

我找到了答案。

我正在使用来自 rails-assets.org 的 gem 'rails-assets-sweetalert2'。说明上说只需要在application.js.

中加上//= require sweetalert2

但是,我发现您还需要添加 //= require es6-promise 因为 gem 'rails-assets-sweetalert2' 依赖于 gem 'rails-assets-es6-promise' 以实现 IE 兼容性.

现在一切正常。