HTML static page Invoke PHP file method _php Tips

Source: Internet
Author: User

This example describes how HTML static pages invoke PHP files. Share to everyone for your reference. The specific methods are as follows:

Static page seems to be unable to directly call the PHP file, but can use JS call way to invoke the PHP file, of course, can also use Ajax invoke PHP file, the following to introduce you:

Give a simple example to illustrate:

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

Copy Code code as follows:
<script type= "Text/javascript" src= "B.php?action=test" ></script>

There is a section of PHP code in b.php:
Copy Code code as follows:
<?php
$action =$_get[' action '];
echo "document.write" ("$action."); n ";
?>

When the a.html file is executed, the b.php file is invoked and the output of the b.php file is executed as a JS statement, and the content is the value of the parameter action passed by JS, which is the value of the action received in the PHP file.

jquery's load function 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 pass parameters

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

2, load a php file, the php file contains a passing parameter
Copy Code code as follows:
$ ("#myID"). Load ("test.php", {"name": "Adam"});


3. Load a PHP file that contains multiple pass parameters. Note: The parameters are separated by commas
Copy Code code as follows:
$ ("#myID"). Load ("test.php", {"name": "Adam", "Site": www.jb51.net});
The imported PHP file contains a pass-through parameter, similar to the following: Test.php?name=adam&site=www.jb51.net


4. Load a php file, the php file with an array as the passing parameters
Copy Code code as follows:
$ ("#myID"). Load ("test.php", {' myinfo[] ', ["Adam", www.jb51.net});
The imported PHP file contains an array pass parameter.

I hope this article will help you with your PHP program design.

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.