The PHP file is called on an html static page,

Source: Internet
Author: User

The PHP file is called on an html static page,

This example describes how to call a PHP file on an html static page. Share it with you for your reference. The specific method is as follows:

The static page does not seem to be able to directly call the PHP file, but you can use js to call the PHP file. Of course, you can also use ajax to call the PHP file. Here we will introduce it to you:

Here is a simple example:
 
For example, you can call the following statement in page a.html to pass the parameter action = test to B. php.
Javascript code
Copy codeThe Code is as follows: <script type = "text/javascript" src = "B. php? Action = test "> </script>
There is such a php code in B. PHP:
Copy codeThe Code is as follows: <? Php
$ Action = $ _ GET ['action'];
Echo "document. write ('". $ action. "'); n ";
?>
B. PHP file, and. the output of the PHP file is executed as a JS statement. The content is the value of the parameter action passed by JS, that is, the value of the action accepted 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 without passing parameters.
Copy codeThe Code is as follows: $ ("# myID"). load ("test. php ");
2. Load a PHP file that contains a passing Parameter
Copy codeThe Code is as follows: $ ("# myID"). load ("test. php", {"name": "Adam "});
 
3. Load a PHP file that contains multiple passing parameters. Note: parameters are separated by commas (,).
Copy codeThe Code is as follows: $ ("# myID"). load ("test. php", {"name": "Adam", "site": www.jb51.net });
// The imported php file contains a passing parameter, similar to: test. php? Name = Adam & site = www.jb51.net
 
4. Load a PHP file. The php file uses an array as the transmission parameter.
Copy codeThe Code is as follows: $ ("# myID"). load ("test. php", {'myinfo [] ', ["Adam", www.jb51.net });
// The imported PHP file contains an array for passing parameters.

I hope this article will help you with php programming.

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.