我想将一个变量从rails视图中的javascript传递给控制器以及其他表单参数。(rails 2.3.5)
<script type="text/javascript">
function confirmation(){
var x=confirm("Edit all copies?");
//passing x and other form object (here @book)
}
</script>
我可以将x转换为rails变量吗?如果有,怎么样?
答案 0 :(得分:0)
我建议构建一个表示表单数据的对象(使用jQuery)并使用AJAX函数将其传递给服务器。
E.g。
var name = $("input#first-name").val();
var age = $("input#last-name").val();
var person = {
name: name || "<no name entered>",
age: age || 0
};
var url = "http://somewhere.com";
$.ajax({
type: "POST",
url: url,
data: person
}).done(function() {
console.log("Success");
});