jQuery表单提交已取消

时间:2019-04-01 05:51:49

标签: javascript jquery

在提交表单时使用jquery使用动态表单提交,显示错误

“由于未连接表单而取消了表单提交”

$('<form method="POST" action="http://localhost/almadar/appointment-form">
 <input type="hidden" name="dept" value="'+dept+'">
 <input type="hidden" name="doctor" value="'+doctor+'">
 <input type="hidden" name="hours" value="'+hours+'">'
).submit();

1 个答案:

答案 0 :(得分:1)

将表格插入dom,然后提交:

var $form = $('<form method="POST" action="http://localhost/almadar/appointment-form"><input type="hidden" name="dept" value="'+dept+'"><input type="hidden" name="doctor" value="'+doctor+'"><input type="hidden" name="hours" value="'+hours+'">')
.appendTo('body')

$form.submit()