Method for html static page to call php file

  • 2021-08-03 09:25:46
  • OfStack

In this paper, an example is given to describe the method of calling php file by html static page. Share it for your reference. The specific methods are as follows:

It seems that php file cannot be directly called in static pages, but js can be used to call php file, and of course ajax can be used to call php file. Let's introduce 1 below:

Give a simple example to illustrate:

The arguments for action=test can be passed to b. php, as called in the following sentence on the page a. html.
Javascript code

<script type="text/javascript" src="b.php?action=test"></script>

There is one PHP code in b. php:
<?php
$action=$_GET['action'];   
echo "document.write('".$action."');n";  
?>

When the a. html file is executed, the b. php file is called, and the output of the b. php file is executed as an JS statement, which is the value of the parameter action passed by JS, that is, the value of 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 an php file with no pass parameters

$("#myID").load("test.php");

2. Load an php file with a pass parameter
$("#myID").load("test.php",{"name" : "Adam"});


3. Load an php file with multiple pass parameters. Note: Parameters are separated by commas
$("#myID").load("test.php",{"name" : "Adam" ,"site":www.ofstack.com});
// Imported php The file contains 1 Passing parameters, similar to: test.php?name=Adam&site=www.ofstack.com


4. Load an php file with an array as the pass parameter
$("#myID").load("test.php",{'myinfo[]', ["Adam", www.ofstack.com});
// Imported php The file contains 1 Arrays pass parameters.

I hope this article is helpful to everyone's php programming.


Related articles: