以下是如何在不离开页面的情况下“执行PHP”。 (+问题) [英] Here is how to 'do PHP' without leaving a page. (+ Question)

查看:87
本文介绍了以下是如何在不离开页面的情况下“执行PHP”。 (+问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处的常见问题解答类似于我如何从

中间输入我的表格发送处理到PHP并将结果返回到页面?


标准答案是你不能因为PHP是服务器端而HTTP是

客户端和服务器之间的桥梁它可以在整个页面中工作>
时间。 (一个请求 - >完整响应)"


但_it是可能的_使用PHP来验证表单输入,因为它输入了

并更新了页面_without_重新加载页面。


这里有两个文件,orville.htm和wilbur.php,它们演示了

方法。 (将两者复制到同一目录并访问orville - wilbur是一个

奴隶。)


有一些限制可能不适合所有人
应用程序,但仍然是一种有趣的技术。


问:我古老的javascript技能限制我进行黑客攻击< input>值。

有没有办法动态访问其他文档位?例如,

有一些简单的文字说服务器回复/某个时间/

(其中''一段时间''从生活开始作为日期(''H:i:s'');在PHP中)。

================== orville.htm === ================== =======

< html>

< head>

<! - 飞行输入概念证明(III)第1页,共2页

辅助窗口/脚本自动打开

- >


< SCRIPT LANGUAGE =" JavaScript">

<! -


function Fly(){

jt =''wilbur.php?VAL =''+ escape(document.frm.bar.value)// escape make

string safe添加到URL

window.open(jt,

'''''''resizable = no,toolbar = no,scrollbars = no,status = no,width = 40高度= 40'')

返回true

}


// - >

< / SCRIPT>

< / head>

< body>


< h1>用于输入验证的飞行屏幕< / h1>

< h2>概念验证< / h2>

< i>此操作与wilbur.php一起< / i>

< p>

< SCRIPT TYPE =" text / javascript">

<! -

d =新日期()

document.write("< b>页面刷新在" + d.toLocaleString()+" ;< / b>< p>")

// - >

< / SCRIPT>


这代表一些仲裁形式< br>

在Bar中键入一些有趣的东西

< p>


< FORM NAME =" frm">

< table bgcolor ="#b0b0b0">

< tr>< td> Foo:< / td> ;< td>< INPUT NAME =" foo" SIZE = 20

VALUE =" Foo">< / td>< tr>

< tr>< td> Bar:< / td> ;< td>< INPUT NAME =" bar" SIZE = 20 VALUE =" abc"

onBlur =" javascript :Fly()" ;;> (自动验证

PHP-land)< / td>< / tr>

<! - 替代内联版本,这意味着<脚本...功能

Fly()... / script>可以省略

Bar:< INPUT NAME =" bar" SIZE = 10 VALUE =" pqr"

onBlur =" window.open(''proofoc6.php?VAL =''+ escape(doc ument.frm.bar.value),

'''',''resizable = no,toolbar = no,scrollbars = no,status = no,width = 40,height = 40'')" ;;>


--->

< tr>< td> Fox:< / td>< td>< INPUT NAME =" fox" SIZE = 20

VALUE =" Fox">< / td>< / tr>

< / table>

< / FORM>

< p>

应该发生的事情是Bar中的值被反转并且Foo得到

被复制到Fox 。< br>

如果< br>

(a)关闭javascript或< br>

(b )弹出窗口被阻止

< p>

注意页面没有重新加载。< br>

其他数据形式保持不变。< br>

< p>

Bar的''验证''是通过发送Bar的值来完成的。

命令行。

这是获取PHP值的方法。

< p>

将Foo复制到Fox是纯粹的javascript,不需要执行

在另一个窗口中

但是证明飞行窗口可以访问此窗口的变量

读写。

< / body>

< / html>

============================== ===============

================== wilbur.php == ==================

<?php


//飞行输入的概念证明(III)2 of 2

//当然这里的PHP很简单,但

//可能是你想要的任何东西。


// --------在PHP世界中--------------

//使用命令行读取当前值

$ currentValue = $ _ GET [''VAL''];


//用它做点什么


如果(!$ currentValue){

$ valbar =''(none)'';

} else {

$ valbar = strrev($ currentValue);

if($ valbar == $ currentValue){$ valbar =''Palindrome'';}

}


// ---------回到Javascript世界------

?>

< html>< head>

< SCRIPT LANGUAGE =" JavaScript">

<! -

opener.document.frm.b ar.value =''<?php print($ valbar);?>''

x = opener.document.frm.foo.value;

opener。 document.frm.fox.value = x;

window.close();

- >

< / SCRIPT>

< / head>

< body>

< / body>

< / html>

========================================== ======== ==

-

PETER FOX因为书店的想法被搁置而不一样
PE ****** @ eminent.demon.co.uk.not.this.bit.no .html

2 Tees Close,Witham,Essex。

埃塞克斯的重力啤酒< http://www.eminent.demon.co.uk>

A FAQ here goes something like "How can I get input from the middle of
my form sent processed to PHP and the result returned to the page?"

The standard answer is "You can''t because PHP is server side and HTTP is
the bridge between client and server and it works in whole pages at a
time. (One request -> complete response)"

But _it is possible_ to use PHP to validate form input as it is being
inputted and update the page _without_ reloading the page.

Here are two files, orville.htm and wilbur.php which demonstrate the
method. (Copy both to same directory and access orville - wilbur is a
slave.)

There are limitations which may not make it suitable for all
applications but nevertheless an interesting technique.

Q: My ancient javascript skills limit me to hacking <input> values. Is
there a way to access other document bits dynamically? For example to
have a bit of plain text that said "The server replied at /some time/"
(where ''some time'' started off life as Date(''H:i:s''); in PHP).
==================orville.htm===================== =======
<html>
<head>
<!-- Proof of concept for flying input (III) page 1 of 2
secondary window/script is automatically opened
-->

<SCRIPT LANGUAGE="JavaScript">
<!--

function Fly(){
jt = ''wilbur.php?VAL=''+escape(document.frm.bar.value) // escape makes
string safe to add to URL
window.open(jt,
'''',''resizable=no,toolbar=no,scrollbars=no,status=n o,width=40 height=40'')
return true
}

//-->
</SCRIPT>
</head>
<body>

<h1>Flying screens for input validation</h1>
<h2>Proof of concept</h2>
<i>This operates in conjunction with wilbur.php</i>
<p>
<SCRIPT TYPE="text/javascript">
<!--
d = new Date()
document.write("<b>Page refreshed at "+d.toLocaleString() + "</b><p>")
// -->
</SCRIPT>

This represents some arbitary form<br>
Type something interesting into Bar
<p>

<FORM NAME="frm">
<table bgcolor="#b0b0b0">
<tr><td>Foo : </td><td><INPUT NAME="foo" SIZE=20
VALUE="Foo"></td><tr>
<tr><td>Bar : </td><td><INPUT NAME="bar" SIZE=20 VALUE="abc"
onBlur="javascript:Fly()";> (Automatically validated in
PHP-land)</td></tr>
<!-- alternative in-line version which means the <script...Function
Fly().../script> can be omitted
Bar : <INPUT NAME="bar" SIZE=10 VALUE="pqr"
onBlur="window.open(''proofoc6.php?VAL=''+escape(doc ument.frm.bar.value),
'''',''resizable=no,toolbar=no,scrollbars=no,status=n o,width=40,height=40'')";>

--->
<tr><td>Fox : </td><td><INPUT NAME="fox" SIZE=20
VALUE="Fox"></td></tr>
</table>
</FORM>
<p>
What should happen is that the value in Bar gets reversed and Foo gets
copied to Fox.<br>
It may not if<br>
(a)javascript is turned off or <br>
(b)popup windows are blocked
<p>
Notice that the page does not get reloaded.<br>
Other data in the form remains intact.<br>
<p>
The ''validation'' of Bar is done by sending the value of Bar on the
command line.
This is the way to get values across to PHP.
<p>
Copying Foo to Fox is pure javascript which doesn''t need to be executed
in another window
but proves that the flying window can access this window''s variables for
read and write.
</body>
</html>
=============================================

==================wilbur.php====================
<?php

// Proof of concept for flying input (III) 2 of 2
// Of course the PHP here is trivial but
// could be anything you want.

// -------- in the world of PHP --------------
// Uses command line to read current value
$currentValue=$_GET[''VAL''];

// do something with it

if(!$currentValue){
$valbar=''(none)'';
}else{
$valbar = strrev($currentValue);
if($valbar==$currentValue){$valbar=''Palindrome'';}
}

// --------- back to the world of Javascript ------
?>
<html><head>
<SCRIPT LANGUAGE="JavaScript">
<!--
opener.document.frm.bar.value=''<?php print($valbar);?>''
x=opener.document.frm.foo.value;
opener.document.frm.fox.value=x;
window.close();
-->
</SCRIPT>
</head>
<body>
</body>
</html>
================================================== ==
--
PETER FOX Not the same since the bookshop idea was shelved
pe******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>

推荐答案

currentValue =
currentValue=


_GET [''VAL''];

//用它做点什么


if(!
_GET[''VAL''];

// do something with it

if(!


currentValue){
currentValue){


这篇关于以下是如何在不离开页面的情况下“执行PHP”。 (+问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆