简体   繁体   English

有没有办法让javascript执行php命令?

[英]Is there a way to have javascript to execute a php command?

I am trying to find a way to may a onclick javascript function execute a mailer script that I have setup on the same page. 我正在尝试寻找一种方法来使onclick javascript函数执行我在同一页面上设置的邮件脚本。 Is this possible? 这可能吗?

<input type="radio" name="power" value="Diesel Powered" onclick="executeMailer()">

您正在寻找AJAX

This is only possible using Ajax or similar. 这仅可使用Ajax或类似方法实现。 Google for it, there are enough tutorials and howtos around. Google为此,周围有足够的教程和操作方法。

No, your javascript has make a request to the server. 不,您的JavaScript已向服务器发出请求。 The server can then execute the php command. 服务器然后可以执行php命令。

You need to do a web request from your javascript code. 您需要通过JavaScript代码进行网络请求。

For instance, if the php code you want to run is located at http://www.yo.com/target.php , you need to make an http request to this page from your javascript code, grab the response and do what you need to do with it. 例如,如果您要运行的php代码位于http://www.yo.com/target.php ,则需要使用您的javascript代码对此页面进行http请求,获取响应并执行您的操作需要这样做。

It is called AJAX. 它称为AJAX。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM