Note that there are some explanatory texts on larger screens.

plurals
  1. POReturning a proper response for post request in Django
    primarykey
    data
    text
    <pre><code>&lt;form id="login_frm" method="post" action = "/login/user_auth/"&gt; &lt;fieldset&gt; &lt;legend&gt;Login:&lt;/legend&gt; &lt;label for="id_email"&gt;Email&lt;/label&gt; &lt;input type="text" name="email" id="id_email" /&gt; &lt;label for="id_password"&gt;Password&lt;/label&gt; &lt;input type="password" name="password" id="id_password" /&gt; &lt;/fieldset&gt; &lt;input name = "login" type="submit" value="Login" /&gt; &lt;/form&gt; $(document).ready(function () { $('#login_frm').submit(function() { var $form = $(this); $.post('/login/user_auth/' , form.serialize(), function(data) { // alert ("function"); alert (data); }); return false; }); }); </code></pre> <p>Django View:</p> <pre><code>def login_user(request): if request.method == 'POST': # perform all logic / and db access data = "hello" return HttpResponse(data) # return HttpResponse ('success.html') </code></pre> <p>I have been stuck on this all afternoon.</p> <ol> <li><p>When I return <code>data</code> as my response, for some reason, the browser displays "Hello" by loading a blank webpage with just "Hello" written on it; in the JavaScript function above, <code>alert (data);</code> is never called (I cannot understand why).</p></li> <li><p>I am unable to render the success.html. I believe that if I write render_to_response inside the HttpResponse, I will solve this problem. However I think making point 1 work is a first priority.</p></li> </ol> <p><strong>Goal</strong></p> <p>After the post, I would like to capture the returned response from the server (whether it is just the "hello" message, or a webpage that displays a success message- stored in "success.html") and display it in place of the <code>login_frm</code> without having the browser refresh a new webpage.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload