简体   繁体   中英

Django Contact form and sending confirmation on page

I got one page. On the page is a contact form. After clicking the 'send' button I want to change the form containing div to 'thank you for mailing us' div. And stay at the same 'id' on the page.

One way to solve it is to put an another template and load it as 'success url' But this way the whole page is being loaded again and the user lands on top of the page without seeing the confirmation.

Is there a way not to load the page again and to change the div somehow? With jQuery for example? How to do it? Is there even an another way?

Would be great to have some hints. Many thanks in advance!

Using Javascript is the easiest solution. Here is example for using AJAX with forms. Django can detect AJAX requests out of the box via request.is_ajax() .

Another option would be to set cookie, redirect to the same url and handle the response differently (depending on given cookie), but that isn't elegant at all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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