HTML static page How to invoke PHP file _php tutorial

Source: Internet
Author: User
Static page looks good you can not call the PHP file directly, but there is a way to invoke the PHP file using JS call, of course, you can also use Ajax to call PHP files Oh, I would like to introduce to you

Give a simple example to illustrate:

You can pass action=test parameters to b.php, as in the following sentence in page a.html.

JavaScript code

The code is as follows Copy Code

There is a PHP code in b.php:

PHP code

The code is as follows Copy Code

echo "document.write ('". $action. "); n ";
?>

When executing the a.html file, the b.php file is called and the output of the b.php file is executed as a JS statement, which is the value of the parameter action of the JS Pass, which is the value of the action accepted in the PHP file.


The load function of jquery is a call that requests another file and loads it into the current DOM.


1, load a php file, the PHP file does not contain transfer parameters

The code is as follows Copy Code
$ ("#myID"). Load ("test.php");

2, load a php file, the PHP file contains a pass parameter

The code is as follows Copy Code
$ ("#myID"). Load ("test.php", {"name": "Adam"});


3. Load a PHP file that contains multiple pass parameters. Note: separated by commas between parameters

The code is as follows Copy Code
$ ("#myID"). Load ("test.php", {"name": "Adam", "Site": www.bKjia.c0m});
The imported PHP file contains a pass-through parameter, similar to the following: Test.php? name=adam&site=www.bkjia.c0m

4. Load a PHP file with an array as the pass parameter

The code is as follows Copy Code

$ ("#myID"). Load ("test.php", {' myinfo[] ', ["Adam", www.bKjia.c0m});
The imported PHP file contains an array pass-through parameter.

http://www.bkjia.com/PHPjc/633075.html www.bkjia.com true http://www.bkjia.com/PHPjc/633075.html techarticle static page looks good you can not call the PHP file directly, but there is a way to invoke the PHP file using JS call, of course, you can also use Ajax to call PHP files Oh, let me give ...

  • 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.