Problem with SUBMIT and ajax
Hello. I am working on a project. and using ajax to check if its a valid username and password. and if it isn't it shows this stuff and doesn't continue to login the user.
but it doesn't seem to do that. it always jsut goes threw and response sometimes isn't set. and my other code to for registration works fine.
Let me provide more information.
If i put a Username and no password it works fine.
if i put a nothing it works
If i put no username but a password it works as intended.
but if i put a bogus password or username to make it invalid it doesn't work.
EDIT: I got it to work to an extent that it now flikkers the message i set once it hits false. but doesn't seem to get to the false. it still goes onto my login.php
- $(document).ready(function(){
- $("form").submit(function(){
- var user = $("#user").val();
- var pass = $("#pass").val();
-
- if(pass != "" && user != "")
- {
- jQuery.ajax({
- type: "POST",
- url: "checklogin.php",
- traditional: true,
- data: {username:user,password:pass},
- cache: false,
- success: function(response){
-
- alert("Num = " +response);
-
- if(response == 1){
- return true;
- }else{
- $('#invalidpu').css('display','block');
- $('#user').css('border', '3px #C33 solid');
- $('#pass').css('border', '3px #C33 solid');
- $('#cross2').fadeIn();
- $('#cross').fadeIn();
- return false;
- }
- }
- });
- }
- else
- {
-
- $('#invalidpu').css('display','block');
- $('#user').css('border', '3px #C33 solid');
- $('#pass').css('border', '3px #C33 solid');
- $('#cross2').fadeIn();
- $('#cross').fadeIn();
- return false;
- }
- });
- });