gpt4 book ai didi

Ruby rails - jquery ajax 提交表单

转载 作者:太空宇宙 更新时间:2023-11-03 16:34:19 26 4
gpt4 key购买 nike

发送 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;
}

最佳答案

用这个肯定有用

    <%= 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 %>

和这个的 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>

享受....

关于Ruby rails - jquery ajax 提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10211032/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com