Javascript 如何在使用表单数据的同时提交表单并调用易趣的API?

Javascript 如何在使用表单数据的同时提交表单并调用易趣的API?,javascript,jquery,ruby-on-rails,forms,Javascript,Jquery,Ruby On Rails,Forms,我正在构建一个ruby on rails应用程序,允许用户以某种形式选择他们想在产品上花费的最高价格,然后将其存储并插入ebay的商品过滤器中,该过滤器是他们api的一部分。但是,我必须先提交表单,然后调用函数来执行api,如何将这两个步骤结合起来 这是表单的代码,它有一个select标签供用户选择其最高价格,还有一个submit按钮,可以正常工作。我尝试添加onclick选项并调用showItems函数来调用ebay API,但它不返回项目 <%= form_tag do |f|

我正在构建一个ruby on rails应用程序,允许用户以某种形式选择他们想在产品上花费的最高价格,然后将其存储并插入ebay的商品过滤器中,该过滤器是他们api的一部分。但是,我必须先提交表单,然后调用函数来执行api,如何将这两个步骤结合起来

这是表单的代码,它有一个select标签供用户选择其最高价格,还有一个submit按钮,可以正常工作。我尝试添加onclick选项并调用showItems函数来调用ebay API,但它不返回项目

    <%= form_tag do |f| %>
      <div>     
        <%= select_tag "max_price", "<option>10</option><option>20</option>".html_safe %>
        <%=submit_tag("Submit filter", id: "form_button", onclick: 'showItems();' ) %>
      </div>
    <% end %>


<!-- this is where the list of items will appear -->
<div id="results"></div>

<!-- this variable is for grabbing the @max_price variable when the form is submitted-->
<% @max_price = params[:max_price]%>


<script>

   [...ebay api taken out to simplify question]

   //this is the function that calls the api and is what I want to call in my form with my form data  
   function showItems() {

    console.log('You are in the show items function')
    // Submit the request
    s=document.createElement('script'); // create script element
    s.src= url;
    document.body.appendChild(s);
   }

</script>