Solved

login using ajax or jquery

Posted on 2010-09-10
4
779 Views
Last Modified: 2012-06-27
I often in somewebsite where the login system is quite nicely build! clicking on a link opens a DIV Box in front of the user machine and user enters his/her credentials, after submit is clicked, it shows shows a loading icon below the DIV after the Password field and if it is wrong, it shows error there and if it is right, it just reloads the page and moves to the members Page!

for me i tried the DIV stuff and its working, but how that jquery of cf inbuild ajax stuff is done, is new, can anyone guide me how that can be achieved

Regards
0
Comment
Question by:myselfrandhawa
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 250 total points
ID: 33655414
0
 
LVL 16

Assisted Solution

by:duncancumming
duncancumming earned 250 total points
ID: 33655787
I started writing this up, then saw that the link leakim971 provided, the first of the Ray Camden articles, does exactly what you need.  The only thing you would need to do is a proper user validation in the processLogin function.  I provide my answer anyway for completeness.

Firstly, build yourself a normal .cfm file that would process a normal form submission.  e.g. something like:

<cfparam name="form.username" default="">
<cfparam name="form.password" default="">

<cfquery name="login" datasource="dsn">
SELECT *
FROM USERS
WHERE USERNAME = <cfqueryparam value="#form.username#" type="string">
AND PASSWORD = <cfqueryparam value="#Hash(form.password)#" type="string">
</cfquery>

<cfif NOT login.recordCount>
  Sorry, this username and/or password not found
<cfelse>
  <cflocation url="members.cfm">  <!--- actually probably not use this, let the calling page do a javascript redirect instead? --->
</cfif>

Plus whatever you want to do maybe with regards putting the user ID into the session or whatever.

Then in your original page, you want to make an AJAX submission to the login page using jQuery.  Two ways to do it, either using .ajax() or .post().  Something like this perhaps:

$(document).ready(function() {
  $('#yourForm').submit(function() {
     $.post("login.cfm", {username: $('#usernameFormField').val(), password: $('#passwordFormField').val()});
  });
});


The second Ray Camden article shows another good way of doing this.  The only thing I think I'm missing here is what you do with the results of the post, but both those links show ways of doing that.
0
 
LVL 15

Author Comment

by:myselfrandhawa
ID: 33710792
I was trying to allocate 50/50 points to both but it closed the question! moderators please make it open again to give 250 points to both

regards
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33752560
Thanks for the points!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now