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

  • Home
  • SEARCH
  • 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 8263641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:10:49+00:00 2026-06-08T04:10:49+00:00

Currently I am trying to implement a login validation system. I am using ajax

  • 0

Currently I am trying to implement a login validation system. I am using ajax so that users can get a response without being redirected to another page. My ajax function sends email and password that user has inputted, and get message in callback function, which can be in three types: email, password, or the actual HttpResponse object. But I have no idea how to render the given http response object using ajax and jquery. Is location.href an option? I am pasting the code below.

In javascript:

function loginSubmit(email, password) {
    var d= "email=" + email + "&password=" + password;
    $.ajax({
        url: "/login",
        type: "POST",
        dataType: "text",
        data: d,
        success: function(m) {
            if (m == "email") {
                $("#emailMessage").html("There is no account associated with this email address.");
                $("#emailError").show();
                $("#emailError").fadeOut(5000, function() {});
            } else if (m == "password") {
                $("#emailMessage").html("There is no account associated with this email address.");
                $("#emailError").show();
                $("#emailError").fadeOut(5000, function() {});
            } else {

            }
        }
    });
}

in view function:

def login(request):
    json = request.POST
    e = json['email']
    p = json['password']

    u = User.objects.filter(email=e)

    if (len(u)):
        up = User.objects.filter(email=e, password=p)
        if (len(up)):
            return render_to_response('profile.html', context_instance=RequestContext(request))
        else:

            data = "password"
            c = RequestContext(request, {'result':data})
            t = Template("{{result}}")
            datatype=u"application/javascript"
            return HttpResponse(t.render(c), datatype)
    else:
        data = "email"
        c = RequestContext(request, {'result':data})
        t = Template("{{result}}")
        datatype=u"application/javascript"
        return HttpResponse(t.render(c), datatype)

p.s. Currently I am using a dummy template and HttpResponse to send data to the ajax success callback function. Is there a more efficient way to accomplish this (send back json data)? I will wait for your replies guys!

  • 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-06-08T04:10:50+00:00Added an answer on June 8, 2026 at 4:10 am
    from django.contrib.auth import authenticate, login as auth_login
    
    def login(request):
    
        # Use authentication framework to check user's credentials
        # http://djangosnippets.org/snippets/1001/ for auth backend
        user = authenticate(
                   email    = request.POST['email'],
                   password = request.POST['password'], )
    
        if user is not None:
            # Use Auth framework to login user
            auth_login(request, user)
            return render_to_response('profile.html',
                     context_instance=RequestContext(request))
    
        else:
            # Return Access Denied
            # Never return bad email/bad password. This is information leakage
            # and helps hackers determine who uses your platform and their emails.
            return HttpResponse("Failed: Bad username or password", status=403)
    
    
    function loginSubmit(email, password) {
        $.ajax({
            url: "/login",
            type: "POST",
            data: {email:email, password:password},
            success: function(data) {
                var returned_html = $(data);
                $("#target_profile_area").clear().append(returned_html);
            },
            error: function(jqXHR) {
                if (jqXHR.statusCode == 403) {
                    $("#loginMessage").text("Your login details are incorrect");
                } else {
                    $("#loginMessage").text("Error Contacting Server");
                }
                $("#loginError").show();
                $("#loginError").fadeOut(5000, function() {});
            }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get a general smooth scrolling mechanism that I can implement in
I'm currently trying to implement some kind of search system in a program of
I'm currently trying to implement a socket server that enables the clients to send
I'm currently trying to implement a Table View on my iPhone app that grabs
Short Working on login system and trying to implement remember me feature. Recently, l
I'm trying to implement ldapRealm on Glassfish 3.1. I can login fine with the
I'm trying to implement system-wide login throttling and I need to calculate the daily
I'm trying to implement an application that coordinates multiple users who are scheduling exclusive
I'm not currently working on a coding project that is trying to implement this,
I'm currently trying to implement the game of Nim using Java, I want to

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.