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