Static HTML method for calling PHP files, _php tutorial

Source: Internet
Author: User

Static HTML method of invoking PHP files,


Static page seems to be unable to directly invoke the PHP file, but you can use the JS call method to invoke PHP files, of course, you can also use Ajax to call PHP files, the following to introduce 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

There is a PHP code in b.php:

 
  

  

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

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

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

$ ("#myID"). Load ("test.php", {"name": "Adam"});


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

$ ("#myID"). Load ("test.php", {"name": "Adam", "Site": Www.shouce.ren});
The imported PHP file contains a pass-through parameter, similar to: Test.php?name=adam&site=www.shouce.ren


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

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

1 JS way to call PHP file and get the value in PHP

Give a simple example to illustrate:

As in the page a.html the following sentence is called:

There is a PHP code in b.php:

When the a.html file is executed, the b.php file is called and the output of the b.php file is executed as a JS statement, so a prompt box pops up with the value of the JS variable jstext, which is the value assigned to Jstext in the PHP file.

Summary:

In the HTML with the JS call file to the PHP file, the output of the PHP file will be called the page as JS code to use.

2 PHP calls the value in JS

There is a piece of code in the z.php page:

3 PHP calls the method (function) in JS


4 JS Call PHP variable

(1)

$userId = 100;
?>

(2)

$url = ' changed URLs '; Defining variables
?>

5-------------------------------

6 Write your own JS and PHP call each other

1.php content:

 
  

  

PHP a good way to invoke JS file
 
  
 
    
 
  
   
  Ok ("aaaaaa!");
 
  

2.php content:

 
  
 
  php$userid=;? >"text" name="userid" id="userid " value=
  " "> PHP 
    
 
  
 
   if( $_get["action"]=="OK " " I ' m ok! " ;} Else  "I ' m not ok! " ;}? >

  

Please Click

  

 
  
 
  

  

 
  
 
  

http://www.bkjia.com/PHPjc/1070669.html www.bkjia.com true http://www.bkjia.com/PHPjc/1070669.html techarticle static HTML calls the Php file method, static page seems to be unable to directly invoke the PHP file, but can use the JS call method to invoke the PHP file, of course, you can also use ...

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