如何在单击Js按钮时执行带有Javascript变量的PHP脚本? [英] How can I execute a PHP script with a Javascript variable on a Js button click?

查看:103
本文介绍了如何在单击Js按钮时执行带有Javascript变量的PHP脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在PHP函数中使用Veriable的同时,使用Javascript文本字段中的Veriable运行PHP代码段。所有这些都应通过单击Javascript按钮执行。



[Js Text]-> js按钮单击->真实的-> PHP(MySQL DB)



附加的示例代码将非常盛行。



谢谢。

解决方案

关键字:AJAX (异步JavaScript和XML)。
使用jQuery,您可以对PHP脚本执行 POST 请求并接收响应。

  $。post( test.php,{名称: John,时间: 2pm})
.done(function(data){
alert( 已加载数据: +数据);
});

请参阅: http://api.jquery.com/jQuery.post/



PS:
在您的PHP中,可以使用: $ _ POST ['name'] / $ _ POST ['time'] 来请求这些变量。 / p>

I would like to run a PHP segment of code with veriables from a Javascript text field while using that veriable in the PHP function. All of that should be executed with a Javascript button click.

[Js Text] --> Js button click --> veriable --> PHP (MySQL DB)

An attached sample code would be grand.

Thanks.

解决方案

KEYWORD: AJAX (Asynchronous JavaScript and XML). With jQuery you can perform a POST request to a PHP script and receive a response.

$.post("test.php", { name: "John", time: "2pm" })
    .done(function(data) {
        alert("Data Loaded: " + data);
    });

See: http://api.jquery.com/jQuery.post/

PS: In your PHP you can use: $_POST['name']/$_POST['time'] to request these variables.

这篇关于如何在单击Js按钮时执行带有Javascript变量的PHP脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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