Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Pull PHP file from Javascript?

Featured Replies

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;
   })
 })

}

  • 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.

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 by Lyndsey

  • 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.

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.