[英]How to run php script from jQuery - on button click
I have a simple PHP script that sits in the home directory of my webserver.我有一个简单的 PHP 脚本,它位于我的网络服务器的主目录中。 I also have a button called "campausebtn".
我还有一个名为“campausebtn”的按钮。 I want to simply click the button and then call the php file using jquery.
我想简单地单击按钮,然后使用 jquery 调用 php 文件。 I've read many posts on SO and it seems simple, but I can't get it to work.
我已经阅读了很多关于 SO 的帖子,看起来很简单,但我无法让它发挥作用。
I've tried the following script:我试过以下脚本:
<script>
jQuery(document).ready(function(){
jQuery("#campausebtn").click(function(){
alert("Paused Clicked!");
$.ajax({
url: 'camera_pause.php',
success: function() {
alert("Paused!");
}
});
});
});
</script>
The "Paused Click" alert is working fine, so I know the jQuery and button are working. “暂停点击”警报工作正常,所以我知道 jQuery 和按钮工作正常。 It just wond't run the script.
它只是不会运行脚本。
Please can someone help?请问有人可以帮忙吗?
Thanks Chris谢谢克里斯
Try it like this...试试这样...
$.ajax({
method: "POST",
url: "camera_pause.php",
})
.done(function( msg ) {
console.log( msg );
});
otherwise read the documentation on it: https://api.jquery.com/jquery.ajax/否则请阅读上面的文档: https://api.jquery.com/jquery.ajax/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.