HTML自体の特定の部分のテキストをJavascriptで抽出して変数に入れ、それをRails側で使えるようにparamsに格納するようにPOSTしたい、
と考えているのですが、
ボタンを押すとajaxによってPOSTされる、というコードを書いたのですが、ボタンをおしてもページが切り替わりません。
何かが間違っているでしょうか?
// dev/form.html.erb <input type="button" value="get_content" onclick="get_content()"/> <script type="text/javascript"> function get_content(){ $.ajax({ url: "dev/index.html.erb", type: "POST", data: {content: { field: "fuga" , field2: "hoge" } }, success: function(resp){ } }); } </script> // dev/index.html.erb # dev#indexで、params['content']を利用して、dev/indexで利用したい。
参考:
https://stackoverflow.com/questions/7237720/jquery-post-to-rails
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。