September 6, 201214 yr Hi guys, New to the forums..been Googling for a while to find a community of developers. Would love a bit of help please, I am creating a HTML login that uses Javascript to check both fields are filled out. It also does some fancy animations that bring up loading screens etc.. What I need to do, in a function..is go to a .php file that checks the credentials against my MySQL database. Now, I can do the PHP bit plus the Javascript is working. But how in the world do I make Javascript connect to the file and then retreive the answer. Ending up by logging in and moving to another page, or displaying an error with another Javascript function. Have googled for the last 3 hours, AJAX comes up alot but I am new to Java. Any help would be much appreciated, here is my Java function: // Controls Login, shows Loading overlay, fades out. Shows loading bg. function Login(){ $("#login").animate({ opacity: 1,top: '49%' }, 200,function(){ $('.userbox').show().animate({ opacity: 1 }, 500); $("#login").animate({ opacity: 0,top: '60%' }, 500,function(){ // Check Login here.. // Connect to PHP file somehow?? // If passed, move on: $(this).fadeOut(200,function(){ $(".text_success").slideDown(); $("#successLogin").animate({opacity: 1,height: "200px"},500); setTimeout( "window.location.href='welcome.php'", 3000 ); }); // If failed, show error. showError("Your Username / Password was incorrect!"); return false; }) }) }
September 6, 201214 yr Hi, I think this may help you http://api.jquery.com/jQuery.post/ if you have problems using it let me know i have a few hours spare tonight
September 6, 201214 yr Author Awww crap, I broke my Javascript. Here is what I tried to do: // Controls Login, shows Loading overlay, fades out. Shows loading bg. function Login(){ $("#login").animate({ opacity: 1,top: '49%' }, 200,function(){ $('.userbox').show().animate({ opacity: 1 }, 500); $("#login").animate({ opacity: 0,top: '60%' }, 500,function(){ $.post['/authlogin.php', {username: $('[name=username]').val(), password: $('[name=password').val()}, function(data) { if(data.success) { $(this).fadeOut(200,function(){ $(".text_success").slideDown(); $("#successLogin").animate({opacity: 1,height: "200px"},500); setTimeout( "window.location.href='welcome.php'", 3000 ); }); } else { showError("Your Username / Password was incorrect!"); $('.inner').jrumble({ x: 4,y: 0,rotation: 0 }); $('.inner').trigger('startRumble'); setTimeout('$(".inner").trigger("stopRumble")',500); setTimeout('hideTop()',5000); }, 'json'); return false; }) }) } The PHP: <?php if($_POST) { if($_POST['username'] == 'test' && $_POST['password'] == 'test') { $data['success'] = true; $data['redrect'] = '/welcome.php'; } else { $data['success'] = false; $data['message'] = "Your info was wrong."; } echo json_encode($data); } ?> Theres an error in the JS, line 72: }, 'json'); Is it because I opened a function with { } in the success function? Not really sure on this. Haha.. Thank you for the link Elite.
September 6, 201214 yr The opening bracket on $.post is wrong it should be $.post( . Secondly, You haven't closed off the if statement inside function(data), you're missing a curly bracket } before this line: }, 'json' }. Apologies for lack of structure, typed quickly on iPad. Edited September 6, 201214 yr by Lyndsey
September 6, 201214 yr I am new to Java. Not that it matters a whole lot but i should mention Javascript an Java are 2 different things
September 6, 201214 yr Author Thank you for your help guys. I got the Javascript working but not doing exactly what I wanted, I've decided Javascript + PHP is a pain. Maybe I will return to it once I learn more, but for now I am going to stick with PHP. Would you say that PHP scripting a whole ticket system would become slow in just PHP? Returning to the server for queries etc etc. Looking at 200 users. Thank you for all your help, Dean.
September 6, 201214 yr Thank you for your help guys. I got the Javascript working but not doing exactly what I wanted, I've decided Javascript + PHP is a pain. Maybe I will return to it once I learn more, but for now I am going to stick with PHP. Would you say that PHP scripting a whole ticket system would become slow in just PHP? Returning to the server for queries etc etc. Looking at 200 users. Thank you for all your help, Dean. No it should not become slow, php can handle a whole lot tbh, even this entire forum your posting on is ran using PHP , but some javascript/jquery deff adds to things
Create an account or sign in to comment