简体   繁体   English

sumbit形式后,colorbox不会关闭

[英]colorbox doesn't close after sumbit form

I have issues with colorbox if I try to submit a form, colorbox remains opened on success. 如果我尝试提交表单,colorbox会出现问题,但成功时colorbox仍保持打开状态。 I tried to add colorbox.close(); 我试图添加colorbox.close(); on success, it worked, but if I try to click the link again to open the form, the form is not displaying - I can see only close button and overlay. 如果成功,它会起作用,但是如果我尝试再次单击链接以打开表单,则该表单不会显示-我只能看到关闭按钮和覆盖。 I tried to hide form and overlay after success, but then again - the form didn't open on second click. 成功后,我尝试隐藏表单并覆盖,但是再一次-再次单击后表单没有打开。

I tried to tweek js file - to assign the same functionality to submit button as close button has, but this of course didn't work properly. 我试图tweek js文件-分配与关闭按钮相同的功能来提交按钮,但这当然不能正常工作。 How to make form close on submit - please suggest. 如何在提交时关闭表格-请提出建议。

The popup form: 弹出形式:

<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>

colorbox call and ajax: 彩盒调用和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>

Try this: 尝试这个:

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