Php modularization for front-end ajax call implementation ajaxphppostjqueryajaxphpajax points

Source: Internet
Author: User
Ajax, php: php modularization for front-end ajax call implementation: Background: The php framework is not used. due to temporary requirements, ajax is required to call the methods in php and a php file is simply written, the file defines two methods, and how to use ajax to call different methods of the same PHP file. The following is the abc. php file. I have defined two methods: Method a and Method B. The following is the Co background: php framework is not used.
Due to temporary requirements, ajax is required to call methods in php. a php file is simply written, and the file defines two methods. ajax is used to call different methods in the same php file.
The following is the abc. php file. I have defined two methods: Method a and Method B.


  

The following is Controller. php. This file is a Controller that calls other specific function classes and plays a pivotal role. it is mainly implemented through reflection.


  hasMethod($method_name)) {                            $func = $class->getmethod($method_name);                            $instance = $class->newInstance();                            $func->invokeArgs($instance, array($_REQUEST));                                              }                }          }         catch (Exception$exc) {                echo$exc->getTraceAsString();          }    }?>

When using ajax, use the following method to call method a in abc. php:

$.ajax({         type:"POST",         url: 'Controller.php?action=abc/a',             dataType: 'json',         success: function(data) {         }      });

If you need to pass parameters, you can write them as follows:

$. Ajax ({type: "POST", url: 'Controller. php ', data: {action = abc/B, parameter 1: 123, parameter 2: 456} dataType: 'json', success: function (data ){}});

'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
  • '). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script

    The above introduces the implementation of php modularization for front-end ajax calls, including ajax and php content, and hopes to help friends who are interested in PHP tutorials.

    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.