我试图得到一个弹出提交按钮工作,但我还没有找到我正在寻找的解决方案。
我使用jquery模态插件向客户端展示他们提交之前更改的内容。然而,当我尝试提交时,什么都没有发生。提交按钮存在于弹出窗口上,而.modify按钮是打开它的按钮。我对弹出框本身没有任何问题。
我的控制台测试正在打印,所以我知道我的事件侦听器没有问题。也许它与event.preventDefault()有关?
提前感谢。
我的代码
后端 jQuery(".modify").click(function() {
event.preventDefault();
var submit = confirm('Are you sure?');
<?php
$post_ids = array();
while($author_entry_posts->have_posts()) : $author_entry_posts->the_post();
array_push($post_ids, get_the_ID());
endwhile;
?>
if (submit == true) {
var data = {
'action': 'modalcall',
'postid': <?php echo json_encode($post_ids)?>,
'userid': <?php echo get_current_user_id() ?>
};
jQuery.post(ajaxurl, data, function(response) {
jQuery(response).appendTo('body').modal();
//Script which handles the submit button on the modal pop-up
jQuery(".modal_submit").click(function() {
console.log("test");
jQuery().submit();
});
});
} else {
return false;
}
});
前端 <input type="submit" name="submit" value="Submit" class="button modal_submit">
在click on modal submit的处理程序中,您没有定义需要提交哪个表单。
jQuery(".modal_submit").click(function() {
console.log("test");
jQuery().submit(); // you are not defining which form to submit.
});
相反,<input type="submit" name="submit" value="Submit" class="button modal_submit">
需要在表单中,需要通过调用jquery submit来提交。
jQuery(".modal_submit").click(function() {
console.log("test");
$(this).closest('form').submit(); // asking to submit the form which contains this button
});