2021年2月5日星期五

My jquery code dosen't seem to be sending data to php, How can we send data to php using jQuery, and how does php receive it?

I have tried using the jQuery post function, but it isn't working, php is not picking up and data, I need this to validate whether or not the user has logged in or not into the app, so we need to send a boolean which tells php if the user is logged in or not, then php will send proper information back to the client, if they are already logged.

This is the jQuery function that I'm using    function check_items(){    let info=[localStorage.getItem("username"),localStorage.getItem("uuid"),localStorage.getItem("school_id")];  if(!info[0]||!info[1]||!info[2]){        let Register="register=false";      $.post("Signup.php",Register,function(){        },"json");    }      }    This is the Signup.php file        <!DOCTYPE html>  <html lang="en">  <head>  <title>Cheater.com</title>  <link href="Signup.css" rel="stylesheet" type="text/css"/>  <script src="Signup.js"></script>  <script src="../JQuery/jquery.js"></script>  </head>  <body >       <?php        class Set_Signup{    function __construct(){      echo " <section id='background'>      <h1 id='title'>Cheater</h1>      <hr>  </section>              <section id='main' >            <form action='../Login/index.php' method='POST' id='signup' onsubmit='check_items()' >              <input type='text' name='username' placeholder='username' class='username' /><br>              <input type='password' name='password' placeholder='password' class='password'/><br>              <input type='text' name='school' placeholder='School Name' class='school' /><br>              <input type='submit' value='Enter' class='enter'/>          </form>        </section>  ";  }  

}

class operations{      function __construct(){}        function recieve_register(){          return $_POST['register'];      }        function handle_user(){            if($this->recieve_register()===false){             //do nothing as javascript will redirect the user to landing.php          }else{              $signup= new Set_Signup();              echo $_POST['register'];           }        }         }      $opp= new operations();  $opp->handle_user();  

?>

https://stackoverflow.com/questions/66071637/my-jquery-code-dosent-seem-to-be-sending-data-to-php-how-can-we-send-data-to-p February 06, 2021 at 06:49AM

没有评论:

发表评论