[英]how to implement ajax in Ruby on rails via jquery
How do I pass a few of my form field(s) values to a controller usnig ajax/jquery? 如何将一些表单字段值传递给控制器usnig ajax / jquery? For example, in php/jquery I do something like this:
例如,在php / jquery中,我执行以下操作:
$("#test-btn").click(function(){
var name=$("#name").val();
var age=$("#age").val();
$.post("insert.php",{name: name,age: age},
function(data){
$("#respone").html(data).hide().fadeIn(500);
});
});
//insert.php
<?php
//insert values to database!
?>
How do I acheive a similar functionality in rails using ajax/jquery? 如何使用ajax / jquery在rails中实现类似的功能?
Depends. 要看。
You can do it the exact same way, which is suitable if you need to manipulate any data. 您可以以完全相同的方式进行操作,这在需要处理任何数据时非常适合。
You can use Rails' UJS's :remote => true
flag and do nothing; 您可以使用Rails的UJS的
:remote => true
标志,什么也不做; here's a quick blog post on it . 这是关于它的快速博客文章 。 This is suitable for when you don't need to do anything other than submit, eg, no manipulation.
当您除了提交之外不需要执行其他任何操作(例如,无需任何操作)时,这非常适合。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.