Home  >  Article  >  Backend Development  >  How to call php files in html static pages_PHP tutorial

How to call php files in html static pages_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:44:43915browse

You can’t call the php file directly in the static page, but you can use the js calling method to call the php file. Of course, you can also use ajax to call the php file. Let me introduce it to you below.

A simple example to illustrate:

For example, if you use the following call in page a.html, you can pass the action=test parameter to b.php.

Javascript code

1. Load a php file that does not contain passing parameters
The code is as follows
 代码如下 复制代码

 

Copy code

 代码如下 复制代码

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

There is this piece of PHP code in b.php:
PHP code

The code is as follows Copy code


代码如下 复制代码
$("#myID").load("test.php");
echo "document.write('".$action."');n";

?>

 代码如下 复制代码
$("#myID").load("test.php",{"name" : "Adam"});


When the a.html file is executed, the b.php file will be called, and the output of the b.php file will be executed as a JS statement. The content is the value of the parameter action passed by JS, which is accepted in the PHP file. The value of the passed action.
 代码如下 复制代码
$("#myID").load("test.php",{"name" : "Adam" ,"site":www.bKjia.c0m});
//导入的php文件含有一个传递参数,类似于:test.php?name=Adam&site=www.bKjia.c0m

jquery’s load function is a call to request another file and load it into the current DOM

 代码如下 复制代码

$("#myID").load("test.php",{‘myinfo[]‘, ["Adam", www.bKjia.c0m});
//导入的php文件含有一个数组传递参数。

The code is as follows Copy code
$("#myID").load( "test.php"); 2. Load a php file, which contains a passing parameter
The code is as follows Copy code
$("#myID").load( "test.php",{"name" : "Adam"}); 3. Load a php file that contains multiple passed parameters. Note: Separate parameters with commas
The code is as follows Copy code
$("#myID").load( "test.php",{"name" : "Adam" ,"site":www.bKjia.c0m}); //The imported php file contains a passing parameter, similar to: test.php? name=Adam&site=www.bKjia.c0m 4. Load a php file that uses an array as a passing parameter
The code is as follows Copy code
$("#myID").load("test.php",{‘myinfo[]‘, ["Adam", www.bKjia.c0m}); //The imported php file contains an array of passed parameters.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/633075.htmlTechArticleThe static page looks good, but you can’t call the php file directly, but you can use the js calling method to call it. php file, of course you can also use ajax to call php files, let me give you...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn