繁体   English   中英

sumbit形式后,colorbox不会关闭

[英]colorbox doesn't close after sumbit form

如果我尝试提交表单,colorbox会出现问题,但成功时colorbox仍保持打开状态。 我试图添加colorbox.close(); 如果成功,它会起作用,但是如果我尝试再次单击链接以打开表单,则该表单不会显示-我只能看到关闭按钮和覆盖。 成功后,我尝试隐藏表单并覆盖,但是再一次-再次单击后表单没有打开。

我试图tweek js文件-分配与关闭按钮相同的功能来提交按钮,但这当然不能正常工作。 如何在提交时关闭表格-请提出建议。

弹出形式:

<div class="body" id="inline-popup">
    <form action="index" method="post" id="form">
        <fieldset>
            <label>Name</label>
            <input type="text" id="name" name="name" />
        </fieldset>

        <fieldset>
            <label>URL (optional)</label>
            <input type="text" name="url" id="url" />
        </fieldset>
        <fieldset>
            <input type="submit" value="ok" class="submit" />
        </fieldset>
    </form>
</div>

彩盒调用和ajax:

    <script>
        $(".popup").colorbox({inline:true, width:"300px", height:"100%"});

$('.submit').on('click', function(e){

        $.ajax({
            type: "POST",
            url: '/pathname/submitForm',
            data: $("#form").serialize(),
            error: function(xhr, ajaxOptions, thrownError, data) {
                err = Array();
                err[0] = "Oops an error is occured";
                    console.log(err);
            },
            dataType: "json",
            success:  function(data) {
                if(data.success=="yes") {
                    console.log(data.success);

                } else {
                    console.log(data.error);
                }
            }
        });
        e.preventDefault();
    });
    </script>

尝试这个:

success:  function(data) {
    if(data.success=="yes") {
        $.fn.colorbox.close();
        console.log(data.success);
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM