[英]Cannot submit form using jquery
I have a problem at submitting a form within sweetalert2 using jquery.我在使用 jquery 在 sweetalert2 中提交表单时遇到问题。
Here's the code that i have:这是我拥有的代码:
<?=form_open_multipart('controller_path','id="form_service"' , ''?>
<input type="button" name="update" id="submit-operate" value="Submit To Operated" class="btn btn-success" onclick="service.submitService()"/>
<?= form_close(); ?>
and this is service.js:这是 service.js:
submitService: function(){
swal({
title: 'Are you sure?',
text: "You will submit this service to the next phase",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Submit'
}).then((result) => {
if (result.value) {
$("#form_service").submit()
}
});
}
The sweetalert works as well, and when I do the console.log
in if(result.value)
it shows on the console, but the form doesn't submit. sweetalert 也可以工作,当我在
if(result.value)
中执行console.log
时,它会显示在控制台上,但表单没有提交。 Can somebody show me the correct way?有人可以告诉我正确的方法吗? Thank you.
谢谢你。
Try this:尝试这个:
submitService = function(){
var form = $("#form_service");
swal({
title: 'Are you sure?',
text: "You will submit this service to the next phase",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Submit'
}).then((result) => {
if (result.value) {
form.submit(); //semicolon in the end
}
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.