: This article mainly introduces ajax + php + Controller to control all background function calls. if you are interested in the PHP Tutorial, refer to it. Reprinted please indicate the source: http://www.cnblogs.com/ghypnus/p/4645873.html
I haven't come here to release code for a long time.
A total of three parts are used to complete the ajax call logic of php. The following is a rough structure:
Part 1: ajax request: mainly the parameter action. LoginController is the php class name, and login is the function name in the LoginController class.
$ ('# Submit '). on ('click', function (e) {e. stopPropagation (); $. ajax ({url :".. /.. /controllers/Controller. php ", data: {action:" LoginController/login ", username: username, password: password}, dataType:" text ", type: 'post', timeout: 10000, error: function () {alert ("server timeout") ;}, success: function (data) {alert (data );}});});
Part 2: Controller. php. This file is used to call controllers of other specific functional classes and plays a pivotal role, mainly through reflection.
hasMethod($method_name)) { $func = $class->getmethod($method_name); $instance = $class->newInstance(); $func->invokeArgs($instance, array($_REQUEST)); $result = $instance->getResult(); echo$result; } } } catch (Exception$exc) { echo$exc->getTraceAsString(); }}?>
Part 3: LoginController. php. This file is a specific function class.
Private $ result;
Function LoginController () {// initialize database connection and other parameters} function login ($ args) {// specific logon logic} function getResult () {return $ this-> result ;}}?>
The above introduces ajax + php + Controller to control all background function calls, including some content, hope to be helpful to friends who are interested in PHP tutorials.