james182 Posted January 6, 2010 Share Posted January 6, 2010 i'm trying to get this ajax login script to work. getting no response from ajax. Please if someone can fix it, that would be great. jquery.js: /*************************************** * LOGIN AJAX ***************************************/ $(document).ready(function() { $('#errorConsole').hide(); $('form[name=admin_login]').submit(function() { $('#errorConsole').slideUp(); $.post('../login.php', { username: $('[name=username]').val(), password: $('[name=password]').val() }, function(data) { if(data.success) { location.href = data.redirect; } else { $('#errorConsole').html(data.message).slideDown(); } }, 'json'); return false; }); }); login.php: if($_REQUEST['action'] == "login"){ if($log->login("logon", $_REQUEST['username'], $_POST['password']) == true){ //do something on successful login $data['success'] = true; $data['redirect'] = '#'; }else{ //do something on FAILED login echo 'WRONG ... '; $data['success'] = false; $data['message'] = 'Oops'; } echo json_encode($data); } Index.php: <div class="box box-50 altbox"> <div class="boxin"> <div class="header"> <h3><img src="_css/img/logo-login.png" alt="CMS Admin" /></h3> <ul> <li><a href="#" class="active">login</a></li><!-- .active for active tab --> <li><a href="#">lost password</a></li> </ul> </div> <FORM id="'.$formname.'" class="'.$formclass.'" method="post" name="'.$formname.'" action="'.$formaction.'" > <!-- Default forms (table layout) --> <div class="inner-form"> <div id="errorConsole" class="msg msg-error"></div> <table cellspacing="0"> * Notify me of replies. <tr> <th><label for="username">Username:</label></th> <td><input class="txt" type="text" id="username" name="username" value="demo" /></td> </tr> <tr> <th><label for="password">Password:</label></th> <td><input class="txt pwd" type="password" id="password" name="password" value="demos" /></td><!-- class error for wrong filled inputs --> </tr> <tr> <th></th> <td class="tr proceed"> <input id="action" value="login" type="hidden" name="action"> <input class="button" type="submit" value="Log in" /> </td> </tr> </table> </div> </form> </div> </div> Quote Link to comment https://forums.phpfreaks.com/topic/187365-php-ajax-login-issues/ Share on other sites More sharing options...
teamatomic Posted January 6, 2010 Share Posted January 6, 2010 What is the error you are getting? HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/187365-php-ajax-login-issues/#findComment-989407 Share on other sites More sharing options...
james182 Posted January 6, 2010 Author Share Posted January 6, 2010 Well thats just it i'm not. nothing happens i should get a response either successful or failed. not getting anything. Quote Link to comment https://forums.phpfreaks.com/topic/187365-php-ajax-login-issues/#findComment-989424 Share on other sites More sharing options...
trq Posted January 6, 2010 Share Posted January 6, 2010 Are you debugging the process using firebug? if not, you should be. Quote Link to comment https://forums.phpfreaks.com/topic/187365-php-ajax-login-issues/#findComment-989430 Share on other sites More sharing options...
Shocker88 Posted January 6, 2010 Share Posted January 6, 2010 You'll want to give us an error to look at where the problem is occuring - don't think many forum goers want to check your syntax for a missing bracket etc.. As thorpe said try using firebug, the plug-in for firefox. Are you sure it is connecting to the database correctly? If you have mysql errors off, it could be an issue. Anyway, anymore information you can provide will help you get an answer a lot. Debug/break it down and try work out what is working in the script and what is not. Quote Link to comment https://forums.phpfreaks.com/topic/187365-php-ajax-login-issues/#findComment-989482 Share on other sites More sharing options...
Jibberish Posted January 6, 2010 Share Posted January 6, 2010 It all looks fine from a syntax point of view, a few things to check are: [*]is the login.php form one directory up? [*]in the login.php, if its sucessfull the data.redirect will be a #, so it wont actually take you anywhere, should this be the name of a page (i.e home.php) [*]also check that $forname etc has what you expect in there, else the bindings wont work Quote Link to comment https://forums.phpfreaks.com/topic/187365-php-ajax-login-issues/#findComment-989531 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.