php按钮点击显示_在html按钮上单击运行PHP功能

每当您通过HTTP请求(即GET,POST,PUT)访问它时,都会运行PHP文件.

您可以使用JQuery / Ajax在按钮点击上发送请求,甚至只需更改浏览器的URL即可导航到PHP地址.

根据POST / GET中发送的数据,您可以有一个运行不同功能的switch语句.

通过GET指定功能

所以在PHP方面你可以有这样的东西:

//see http://PHP.net/manual/en/function.call-user-func-array.PHP how to use extensively

if(isset($_GET['runFunction']) && function_exists($_GET['runFunction']))

call_user_func($_GET['runFunction']);

else

echo "Function not found or wrong input";

function test()

{

echo("test");

}

function hello()

{

echo("hello");

}

?>

您可以使用地址栏做最简单的获取请求作为测试:

http://127.0.0.1/test.PHP?runFunction=hellodddddd

结果是:

Function not found or wrong input

http://127.0.0.1/test.PHP?runFunction=hello

结果是:

hello

发送数据

通过JQuery获取请求

$.get("test.cgi",{ name: "John"})

.done(function(data) {

alert("Data Loaded: " + data);

});

POST请求通过JQuery

$.post("test.PHP",{ name: "John"} );

通过Javascript位置获取请求

value="insert button text here"

onClick="self.location='Your_URL_here.PHP?name=hello'">

阅读数据(PHP)

有用的链接

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值