search
HomeBackend DevelopmentPHP TutorialHow to call php files from static html, _PHP tutorial
How to call php files from static html, _PHP tutorialJul 12, 2016 am 09:05 AM
htmlphpgooddocumentmethodoftransferstaticpage

Static html method of calling php files,

It seems that the php file cannot be called 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:
Example A simple example to illustrate:

If you use the following call in page a.html, you can pass the action=test parameter to b.php.
Javascript code

There is this piece of 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 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.
The load function of jquery is a call that requests another file and loads it into the current DOM
1. Load a php file, which does not contain passed parameters

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

2. Load a php file, which contains a passing parameter

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


3. Load a php file that contains multiple passed parameters. Note: Separate parameters with commas

$("#myID").load("test.php",{"name" : "Adam" ,"site":www.shouce.ren});
//The imported php file contains A passing parameter, similar to: test.php?name=Adam&site=www.shouce.ren


4. Load a php file that uses an array as a passing parameter

$("#myID").load("test.php",{'myinfo[]', ["Adam", www.shouce.ren});
//The imported php file contains a Array parameters are passed.

1 Call the PHP file using JS and get the value in php

Give a simple example to illustrate:

For example, in page a.html, use the following sentence to call:

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

<script type="text/javascript" >

alert(jstext);

</script>

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

$action=$_GET['action']; //echo "var jstext='$action'"; //Output a JS statement, generate a JS variable, and assign the value to the PHP variable $ The value of action //echo "var jstext='aa'"; echo "var jstext="."'$action'"; ?>

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, so a prompt box will pop up here with the value of the JS variable jstext. That is the value assigned to jstext in the PHP file.

Summary:

Use JS to call the file in HTML to call the PHP file, and the output of the PHP file will be used as JS code by the calling page.

2 php calls the value in js

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

$key=""; echo $key; ?>

3 php calls methods (functions) in js


< ;?php echo ""; ?>

4 JS calls PHP variables

(1)

$userId=100;
?> <script><br />var userId;<br />userId=document.getElementByIdx_x_x_x("userId").value;<br /> alert (userId);<br /></script>

(2)

$url = 'changed URL'; //Define variables
?>

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

var Y=,M=,D=;

-->

6 The js and php written by yourself call each other

1.php content:

<?php

//echo "<script LANGUAGE='javascript'>alert('$php变量');</script>";   //最简单的php调用js

//echo "<a href=#><img     style="max-width:90%"$fruit_pic_array[$i]' onMouseOver=&rsquo;javascript:a();&lsquo; alt="How to call php files from static html, _PHP tutorial" ></a>";

//echo "<a href='3.php'>aaaa</a>";   //php中超链接

//echo "<script type='text/javascript' language='javascript'>phpmake('PHP建站学习笔记网');</script>";   //有时候需要在PHP执行过程中,需要调用JavaScript自定义函数(验证时出错)

echo "function ok(msg){alert(msg);}";

?>

 

<HTML>

<HEAD>

<TITLE> php调用js文件的好办法</TITLE>

</HEAD>

<BODY>

<!--js调用php中定义的js-->

<scrīpt language=''javascrīpt'' type=''text/javascrīpt'' src=''1.php''></scrīpt>  

<scrīpt>

ok("aaaaaa!");

</scrīpt>

</script>

</BODY>

</HTML>

 

2.php content:

<!--js调用php-->

<?<span>php

$userId</span>=<span>100</span><span>;

</span>?>

<script>

<span>var</span><span> userId;

userId</span>=document.getElementByIdx_x(<span>"</span><span>userId</span><span>"</span><span>).value;

alert (userId);

</span></script>

<input type=<span>"</span><span>text</span><span>"</span> name=<span>"</span><span>userId</span><span>"</span> id=<span>"</span><span>userId</span><span>"</span> value=<span>"</span><span><?php echo $userId; ?></span><span>"</span>>

<!--js调用php-->

<?<span>php

</span><span>if</span>($_GET[<span>"</span><span>action</span><span>"</span>]==<span>"</span><span>ok</span><span>"</span><span>)

{

echo </span><span>"</span><span>I'm OK!</span><span>"</span><span>;

}

</span><span>else</span><span>

{

echo </span><span>"</span><span>I'm not OK!</span><span>"</span><span>;

}

</span>?>

<SCRIPT Language = "JavaScript">

function func()

{

if(confirm("Are you OK with this?"))

{

this.location = "ok.php?action=ok";

}

else

{

this.location = "ok.php?action=cancel";

}

}

</SCRIPT>

 

<html>

<head>

</head>

<body>

<a href="#" href="#" onClick="javascript:func();">Please Click</a>

</body>

</html>

 

<!--js调用php-->

<html>

<head>

<script>

function isMail(PostString) 

{ 

re=/\w*/ 

if(re.test(PostString)) 

{ 

return true; 

} 

else 

{ 

return false; 

} 

} 

function test(){

if (isMail(<?php echo $email?>)) 

{document.write("<?php echo "N";?>");} 

else 

{document.write('<?php echo 'Y';?>');}

}

</script>

</head>

<body>

<?php 

$email="aa"; 

?>

<input   type=button   value=click   onclick= 'test() '>

</body>

</html>

 

<!--php中含有js代码-->

<?php

    echo   "

<script   language=javascript>

  function   test(){

    alert( 'hello ');    

  }

</script> ";

?>

<input   type=button   value=click   onclick= 'test() '>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1070669.htmlTechArticleHow to call php files in static html. It seems that php files cannot be called directly in static pages, but it is You can use js calling method to call php files, of course you can also use...
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
web前端笔试题库之HTML篇web前端笔试题库之HTML篇Apr 21, 2022 am 11:56 AM

总结了一些web前端面试(笔试)题分享给大家,本篇文章就先给大家分享HTML部分的笔试题(附答案),大家可以自己做做,看看能答对几个!

深入解析C语言中static关键字的作用和用法深入解析C语言中static关键字的作用和用法Feb 20, 2024 pm 04:30 PM

深入解析C语言中static关键字的作用和用法在C语言中,static是一种非常重要的关键字,它可以被用于函数、变量和数据类型的定义上。使用static关键字可以改变对象的链接属性、作用域和生命周期,下面就来详细地解析一下static关键字在C语言中的作用和用法。static变量和函数:在函数内部使用static关键字定义的变量称为静态变量,它具有全局生命周

PHP中私有静态方法的作用及应用场景PHP中私有静态方法的作用及应用场景Mar 23, 2024 am 10:18 AM

PHP中私有静态方法的作用及应用场景在PHP编程中,私有静态方法是一种特殊的方法类型,它只能在定义它的类内部访问,外部无法直接调用。私有静态方法通常用于类的内部逻辑实现,提供了一种封装和隐藏细节的方式,同时又具有静态方法的特性,可以在不实例化类对象的情况下被调用。下面将探讨私有静态方法的作用及应用场景,并提供具体的代码示例。作用:封装和隐藏实现细节:私有静态

HTML5中画布标签是什么HTML5中画布标签是什么May 18, 2022 pm 04:55 PM

HTML5中画布标签是“<canvas>”。canvas标签用于图形的绘制,它只是一个矩形的图形容器,绘制图形必须通过脚本(通常是JavaScript)来完成;开发者可利用多种js方法来在canvas中绘制路径、盒、圆、字符以及添加图像等。

快速掌握静态相对定位的技巧与方法快速掌握静态相对定位的技巧与方法Jan 18, 2024 am 11:18 AM

快速静态相对定位是网页开发中非常重要的一种定位方式。它可以使元素相对于其正常位置进行微调的同时,仍然保持在文档流中的位置。在本文中,我将详细介绍快速静态相对定位的使用方法,以及一些常见的应用场景。首先,我们需要了解快速静态相对定位的基本概念。在CSS中,元素的定位方式有四种:静态定位、相对定位、绝对定位和固定定位。静态定位是默认的定位方式,元素的位置通过文档

html5废弃了哪个列表标签html5废弃了哪个列表标签Jun 01, 2022 pm 06:32 PM

html5废弃了dir列表标签。dir标签被用来定义目录列表,一般和li标签配合使用,在dir标签对中通过li标签来设置列表项,语法“<dir><li>列表项值</li>...</dir>”。HTML5已经不支持dir,可使用ul标签取代。

html中document是什么html中document是什么Jun 17, 2022 pm 04:18 PM

在html中,document是文档对象的意思,代表浏览器窗口的文档;document对象是window对象的子对象,所以可通过“window.document”属性对其进行访问,每个载入浏览器的HTML文档都会成为Document对象。

html5支持boolean值属性吗html5支持boolean值属性吗Apr 22, 2022 pm 04:56 PM

html5支持boolean值属性;boolean值属性指是属性值为true或者false的属性,如input元素中的disabled属性,不使用该属性表示值为flase,不禁用元素,使用该属性可以不设置属性值表示值为true,禁用元素。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),