我可以使用jquery ajax从php类调用该函数吗?

I begin with an object-oriented programming in php.

I want to do the logging - using ajax and jquery.

EDIT: Can I call the function ajax from file jquery.php - using jquery AJAX?

//FILE jquery.php

class jquery {

    public function ajax() {

    echo "result";      

    }
}

If you make an ajax call similar to this :

http://example.com/ajax.php?firstParam=1

Within your ajax.php file you can do something like this :

switch($_GET['firstParam']){
 case "1":
  callYourFunction();
 break;
 case "2":
  someOtherFunction();
 break;
}

This is a very stripped down example... In a real world case you would have to take security into account and sanitize any information you are getting from outside your server (i.e. from a user).

The names I have given are only place holders - you can change the function/variable names to whatever you feel comfortable with.

I hope this sheds some light on your conundrum.

You cannot call a class directly - but you can fetch the result of an execution.

Here an example how you can call it nearly direct - but don't use this for critical login code.

<?php
$ftcn = $_GET['getname'];
$bc = new ReallyBadCode();
$bc->$ftcn();

class ReallyBadCode{
    function test(){
    }

    function __call($name, $args){
       $this->$name($args);
    }

}

Not sure if you completely understand what AJAX is, but it's an acronym for Asynchronous JavaScript and XML. With Ajax, web applications can send data to, and retrieve data from, a server asynchronously (in the background) without interfering with the display and behaviour of the existing page. That's it.

This I believe is what you're looking for (though its not OOP, but im not writing an entire OOP login to try answer your question)

File: login.php

<?php
  $db = new PDO("mysql:host=localhost;dbname=database", SQL_USER, SQL_PASS );

  $stmt = $db->prepare('SELECT user_id, user_activated FROM users WHERE ( username = AND user_password = ? LIMIT 1');
  $stmt->execute( array( $_POST['u'], $_POST['p'] ) );

  if( $stmt->rowCount() == 1 )
  {
     // Authentication session storage stuff here
     echo 'Logged in';
  }
  else
  {
     echo 'bad login';
  }
?>

So you could have a HTML page with something like:

<div id="results"></div>

<input type="text" id="txtUsername" /> <br />
<input type="password" id="txtPassword" /><br />
<button id="cmdLogin">Login</button>

<script>
  $(document).ready(function(){
     $("#cmdLogin").click(function(){
        $u = $("#txtUsername").val();
        $p = $("#txtPassword").val();

        $.ajax({
              type: "POST",
              url: "http://yoursite.com/login.php",
              data: "u="+u+"&p="+p
            }).done(function(results) { 
                  $("#results").html(results).hide().fadeIn();
            });
     });
  });
</script>

Also, keep in mind this code is un-tested and written it as replying to this, so don't treat this as a solution to what you're wanting, but rather a resource to help you to implement what it is you're asking for.