【问题标题】:SyntaxError: missing ) after argument list rails 5.2.2SyntaxError: missing ) after argument list rails 5.2.2
【发布时间】:2019-02-11 16:13:49
【问题描述】:

我正在开发一个简单的 Rails 应用程序。我需要使用 ajax 发出请求,但它不起作用。我有 jquery-rails,并在 application.js 中添加了 jquery 引用(需要)

    <%= form_with(model: article, local: true) do |form| %>
        <%= form.select(:resource_id, [['Opc 1',1],['Opc 2',2]]) %>
        <script>
        $('select#article_resource_id').on('change', function(event) {
            var selected_resource_id = $(this).val();
            $.ajax('/relative/path/to/your/action', data: { id: selected_resource_id })
        })
        </script>
    <% end %>

这是我的错误: SyntaxError: missing ) after argument list[了解更多]

【问题讨论】:

    标签: jquery ruby-on-rails ajax


    【解决方案1】:
    $.ajax('/relative/path/to/your/action', data: { id: selected_resource_id })
    

    应该是

    $.ajax('/relative/path/to/your/action', { data: { id: selected_resource_id } })
    

    第二个参数应该是设置,其中data 是查询字符串中元素的对象关键字。

    参考。 http://api.jquery.com/jQuery.ajax/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-13
      • 1970-01-01
      相关资源
      最近更新 更多