Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4065228
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:57:24+00:00 2026-05-20T15:57:24+00:00

This is my second foray into Ajax and I’m not quite sure how to

  • 0

This is my second foray into Ajax and I’m not quite sure how to pull this off.

So I have a modal window that opens when an anonymous user attempts to perform a certain task. The window contains a user signup form that I then $.post to my Django login view. If username/password are valid, user is logged in an status code of 1 is returned as the response. IF not, a status of 0 is returned.

When I try to do it outside of js, it works. However, within my script, it fails. I think that it has to do with the response content_type and how I’m interpreting it. I’m not sure.

def login_async(request):       
if request.method=='POST' and len(request.POST['username'])<20 and len(request.POST['password'])<20:
    username=request.POST.get('username', '') #probably need to script tags here
    password=request.POST.get('password', '')
    user=auth.authenticate(username=username, password=password)
    if user is not None:
        auth.login(request,user)
        status=1
        response=HttpResponse()
        response['Content_Type']="text/html"
        response.write(status)
        return response
    else:
        status=0
        response=HttpResponse()
        response['Content_Type']="text/html"
        response.write(status)
        return response




$('input#login').click(function(event){
    $.post("/login_async/", {username:$('input[name=username]').val(), password:$('input[name=password]').val()}, //could also use $(this).serialize() here to capture all form inputs
        function(data){
            if(data==1){
                $('#login').dialog("close");
                }
    });
    });

What’s the problem here? I initially tried to return the response as JSON but I couldn’t figure out how to make serialize.serializers(“json”,status) work. I kept getting an error.

One last question…

If I get a valid status (user is signed in), that will influence the behavior of modal windows on the page. The modal windows open based on logged in status. If a user is signed in, one set of windows open on a click event, and vice versa. This toggle is dependent on Django context {% user.is_authenticated %}.

That context renders only once right, on page load? Can I do anything to communicate the status change to the modal windows that’s secure from easy hacks?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:57:24+00:00Added an answer on May 20, 2026 at 3:57 pm

    It should be Content-Type. If that doesn’t fix your problem, try adding a dataType parameter at the end of the $.post call.

    $.post("/login_async/", {}, function(data){
      // fancy stuff
    }, "html");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Linux gcc 4.4.1 I have this function that passes this second parameter that casts
I have a Person class that inherits PersonBase and this second class inherits EntityBase
I have a view that pushes another view with navigation controller. In this second
this is the second game that I'm having issues with in the same area...
I have the following paragraphs: <p>This is a first paragraph.</p> <p>This is a second</p>
I am following this tutorial as a first foray into bootloader/OS development for x86
Why is batch not running this second for loop? What am i doing wrong?
I have this vague recollection reading about groovy that there exists a '??' sugar
I dont have time right this second to put some sample code, (Ill edit
Say I have an object such as this: var time = { 'second': 1000,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.