在Rails中使用remote:true在Chrome中有效,但在Safari中无效——从js.erb文件调用succe

Using remote: true in Rails is working in Chrome, but not in Safari - seems to be an issue in calling the success function from the js.erb file

本文关键字:无效 js erb succe 调用 文件 Safari Rails remote 有效 Chrome      更新时间:2023-09-26

我有一个嵌套表单(使用nested_form gem),我在上面调用remote:true。

= nested_form_for @shopping_list, :remote => true, :html => {:class => "shopping-list-    form"} do |f|

我将其链接到控制器中的创建操作,成功函数从create.js.erb文件返回以下内容:

closeShoppingListForm();
$("#submit-success").delay(500).fadeIn(500);
$("#submit-success").delay(2000).fadeOut(500);
$.getScript(this.href);
return false;

Chrome的一切都很顺利-还没有测试Firefox。Safari以前也遇到过这个问题,但上次它是一个缺少结尾";"的函数——从js.erb文件中获取成功函数不是问题。

这是closeShoppingListForm函数页面的js文件中的代码——它完全按照听起来的方式——关闭了一堆东西:

function closeShoppingListForm() {
  $("#shopping-list-form").hide();
  $("#running-total").hide();
  $("#total").hide();
  $("#create-shopping-list").fadeIn(500);
  $(".icon-remove").trigger("click");
  $("#shopping_list_name").val('');
  $("#total").html('');
 inventoryItemsQuantities = new Array();
};

我在谷歌上搜索SO已经有一段时间了,但现在是时候提交它了,看看是否有其他人遇到过这个问题。任何帮助都是最受欢迎的——非常感谢您的关注。

如果需要任何其他代码片段,请告诉我。

谢谢!

简单的修复…我们看了一会儿,发现只是我走得太快,在.getScript…之后抛出了"return false"

也许这将帮助其他人不犯同样的错误。

closeShoppingListForm();
$("#submit-success").delay(500).fadeIn(500);
$("#submit-success").delay(2000).fadeOut(500);
$.getScript(this.href);