ajax - $.post into a php class function -


i want make live username check , want use php function.

--> <?php     require '../../core/init.php'; ?> <!doctype html> <html lang="de"> <head>     <meta charset="utf-8">     <title>k&ouml;ppcms - registrieren</title>     <link rel="stylesheet" href="../../../css/style.css">     <script type="text/javascript" src="../../../js/jquery.js"></script>     <script type="text/javascript" src="../../../js/footer.js"></script>     <script type="text/javascript">         $(document).ready(function() {             $("#username").keyup(function (e) {                  //removes spaces username                 $(this).val($(this).val().replace(/\s/g, ''));                  var username = $(this).val(); //get string typed user                  $.post('users.php', {'username':username}, function(data) { //make ajax call users.php                     $("#user-result").html(data); //dump data received php page                 });              });         }); </script> </head> 

init.php:

<?php session_start(); require 'database/connect.php'; require 'classes/users.php'; require 'classes/general.php';  $users         = new users($db); $general     = new general();  $errors     = array(); ?> 

so how can call check_username function , send values it? hope understand question, because english isn't good.

i'd tried in users.php:

<?php $users = new users($db); echo $users->check_username($_post['username']); class users{     private $db;      public function __construct($database) {         $this->db = $database;     }      public function check_username($data) {         return $data+1;     }     function func1($data){         return $data+1;     }  } 

get error:

notice: undefined variable: db in c:\xampp\htdocs\kcms\system\cms\user\users.php on line 2 

enter image description here

your php script should like:

<?php require('init.php'); // contains $users = new users($db); echo $users->check_username($_post['username']); 

for using return value in javascript, see

how return response asynchronous call?


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -