Submit a form in a popup, and then close the popup

后端 未结 5 1625
终归单人心
终归单人心 2020-12-13 05:23

This seemed so trivial when I started off with it! My objective is this:

  • When user clicks on a button, open up a form in a new window.
  • Once the form
5条回答
  •  醉梦人生
    2020-12-13 05:39

    The Solution on top won't work because a submit redirects the page to the endpoint of form and wait for response to redirect. I see that this is an old Question but Most Asked and even i came to know the answer.Still here is my solution what i am implementing. I tried to keep it secure with Nonce but if you don't care then not required.

    Method 1: You need to Pop up the form.

    document.getElementById('edit_info_button').addEventListener('click',function(){
            window.open('{% url "updateuserinfo" %}','newwindow', 'width=400,height=600,scrollbars=no');
        });
    

    Then you have the form open.

    Submit the form normally.

    Then return an HTTPResponse in render to a template(HTML file) With a STRICT Content Security Policy. A Variable that contains the following script. Nonce contains a Base64 128bits or larger randomly generated string for every request made to server.

    Method 2:

    Or you can redirect to another Page which is suppose to close ... Which already Contains the window.close() script. This will close the pop up window.

    Method 3:

    Otherwise the simplest will be Use a Ajax call if you are comfortable with one.Use then() and check your condition to the httpresponse from the server.Close the window when success.

提交回复
热议问题