我有一个Rails表单。但是我不想通过Rails提交表单。我想通过Ajax提交。
在查看文件中
<li><%= submit_tag 'Save', id: 'submit', :class => 'button' %></li>
在js文件中
$(".submit").click(function() {
alert("hi");
event.preventDefault();
health_marks_array = form_hash_and_submit();
if (0 < health_marks_array.length) {
call_form_submit(health_marks_array);
}
else{
location.href = '/thinking_health_card/health_marks/new?form_name=' + form_name + '&student_id=' + student_id + '&health_exam_id=' + health_exam_id
}
return false
});
也试过了
$(".submit").click(function(event) {
alert("hi");
event.preventDefault();
health_marks_array = form_hash_and_submit();
if (0 < health_marks_array.length) {
call_form_submit(health_marks_array);
}
else{
location.href = '/thinking_health_card/health_marks/new?form_name=' + form_name + '&student_id=' + student_id + '&health_exam_id=' + health_exam_id
}
return false
});
为什么它不起作用?
改变,从
$(".submit").click(function() {});
到
$("#submit").click(function(event) {
event.preventDefault();
....
});
元素具有id #submit
,而不是class.submit
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句