Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
RubyRails-jQueryAjax提交表单_Ruby_Ajax_Ruby On Rails 3 - Fatal编程技术网

RubyRails-jQueryAjax提交表单

RubyRails-jQueryAjax提交表单,ruby,ajax,ruby-on-rails-3,Ruby,Ajax,Ruby On Rails 3,发送ajax请求是否正确? 此代码不起作用,我需要在此处更改什么?还有更好的发送ajax表单的方法吗 <%= form_tag item_create_path, :remote => true, :id => 'create_item' do %> <p> <b> <%= label_tag :"Name" %></b> <%= text_field_tag :name, nil, :maxlength

发送ajax请求是否正确? 此代码不起作用,我需要在此处更改什么?还有更好的发送ajax表单的方法吗

<%=  form_tag item_create_path, :remote => true, :id => 'create_item'  do %>
  <p>
   <b> <%= label_tag :"Name" %></b> <%= text_field_tag :name, nil, :maxlength => 40, :size => 70 %>
   <b> <%= label_tag :"Date" %></b> <%= text_field_tag :date, nil, :maxlength => 10, :size => 10, :value => Time.now.utc.strftime("%Y-%m-%d") %>
   <b> <%= label_tag :"Time" %></b> <%= text_field_tag :time, nil, :maxlength => 10, :size => 10, :value => Time.now.localtime.strftime("%H:%M:%S") %>
   </p>
  <p>
   <b> <%= label_tag :Description %></b> <%= text_field_tag :description, nil, :maxlength => 50, :size => 50 %>
  </p>

<%= hidden_field_tag :type, nil, :value => "new" %>
<p class="button"><%= submit_tag "  Create  ",:onclick=>"javascript:submitForm()" %></p>
<% end %>


function submitForm() {
    $.ajax({type:'POST', url: '/item/create', data:$('#create_item').serialize(), success: function(response) {
        $('#create_item').find('#item').html(response);
    }});

    return false;
}
true,:id=>'create_item'do%>

40,:大小=>70%>
10,:size=>10,:value=>Time.now.utc.strftime(“%Y-%m-%d”)%%>
10,:size=>10,:value=>Time.now.localtime.strftime(“%H:%M:%S”)%%>

50,:大小=>50%>

“新”%>

“javascript:submitForm()”%>

函数submitForm(){ $.ajax({type:'POST',url:'/item/create',data:$('#create_item')).serialize(),success:函数(响应){ $(“#创建#项”).find(“#项”).html(响应); }}); 返回false; }
使用这个,它肯定会工作的

    <%= form_for(:customer, :url => {:controller => "subscribers", :action => "change_password"}, :html => {:id => 'edit_password_form', :method => :get, :onsubmit => "return false;"}) do |f| %>
      <%= hidden_field_tag "ids", :id => "ids"%>
      <div class="ports-fields">
        <div class="pass">
          <label style="margin-top:4px;">Password</label> 
          <%= f.password_field :password, :class=> 'fields', :placeholder => 'Password' %>
        </div>
        <div class="pass">
           <label>Confirm Password</label> 
           <%= f.password_field :password_confirmation, :class=> 'fields', :placeholder => 'Password Confirmation' %>
        </div>
        <div class="change-pass-btn-submit"> 
           <%= submit_tag "CHANGE PASSWORD", :id => "edit_password_btn" %>
        </div>
        <!--modify ports ends-->
      </div>
    <% end %>
{:controller=>“subscribers”,:action=>“change_password”},:html=>{:id=>“edit_password_form”,:method=>:get,:onsubmit=>“return false;”})do | f |%>
“ids”%>
密码
'字段',:占位符=>'密码'%>
确认密码
'字段',:占位符=>'密码确认'%>
“编辑密码\u btn”%>
和jquery代码

   <script type="text/javascript">
       $("#edit_port_btn").click(function() {
            var container = $("#info");
            $("#edit_port_form").submit(function() {
                $(this).unbind('submit').ajaxSubmit({
                    success: function(data) {
                        container.html(data);
                        hudMsg('success', 'Modify ports successfully.');
                    }
                })
            }); 
       });
   </script>

$(“#编辑_端口_btn”)。单击(函数(){
变量容器=$(“#信息”);
$(“编辑端口表单”)。提交(函数(){
$(this).unbind('submit').ajaxSubmit({
成功:功能(数据){
html(数据);
hudMsg('success','modifyport successfully');
}
})
}); 
});
快乐