Javascript 表单提交 [英] Javascript Form Submition

查看:51
本文介绍了Javascript 表单提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在单击提交时刷新表dashboard_categories"而不刷新整个页面,这是我到目前为止所做的:http://pastie.org/7822560

I'm looking to refresh the the table "dashboard_categories" when I click submit without the whole page refreshing, this is what I've done so far: http://pastie.org/7822560

由于我是一个完整的新手,我现在专注于我用 Javascript 做的事情.我知道我必须捕捉表单提交,发送数据,然后调用部分刷新......但不知道如何.有任何想法吗?

I'm now stuck on what I do with Javascript as I'm a complete novice. I know I have to catch the form submission, send the data and then call the partial to refresh... but have no clue how. Any ideas?

希望我离你不远......

Hopefully I'm not far off...

我在 index.html.erb 上有一个用于 javascript 的 content_for 标记:

I've got a content_for tag for the javascript on index.html.erb:

<% content_for :javascript do %>
  <script type='text/javascript'>

  </script>
<% end %>

推荐答案

在清单中包含不显眼的 javascript 驱动程序 app/assets/javascript/application.js:

Include unobtrusive javascript driver in your manifest app/assets/javascript/application.js:

//= require jquery_ujs

然后标记AJAX要提交的表单:

And then mark the form to be submitted by AJAX:

<%= form_for(@category), remote: true do |f| %>

这篇关于Javascript 表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆