This seemed so trivial when I started off with it! My objective is this:
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.