Ajax + php + Controller controls all background function calls. ajaxcontroller_PHP tutorial

Source: Internet
Author: User
Ajax + php + Controller controls all background function calls and ajaxcontroller. Ajax + php + Controller controls all background function calls. for details about ajaxcontroller, refer to the source: www.cnblogs.comghypnusp4645873.html. I haven't been here for a long time, and I have released code. ajax + php + Controller controls all background function calls.

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

Http://www.bkjia.com/PHPjc/1031814.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1031814.htmlTechArticleajax + php + Controller control all the back-end function call, ajaxcontroller reprint please indicate the source: http://www.cnblogs.com/ghypnus/p/4645873.html for a long time didn't come here to publish the code total...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.