在jQuery单击中运行php函数 [英] Run php function inside jQuery click
本文介绍了在jQuery单击中运行php函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在jQuery click事件中运行PHP函数。我有以下哪些不正确。当用户点击一个按钮时,我想要一个新的直接创建。
How do i run a PHP function inside jQuery click event. I have the following which is not correct. when the user clicks on a button, i want a new directly created.
$('button').click(function(){
<?php mkdir('/test1/test2', 0777, true); ?>
return false;
})
推荐答案
您无法在jquery函数中运行PHP。 PHP在服务器端运行,而jquery / javascript在客户端运行。但是你可以使用jquery请求一个php页面,并在该页面中使用PHP代码运行你想要的mkdir。
You cannot run PHP inside a jquery function. PHP is run on the server side whereas jquery/javascript is run on the client side. However you can request a php page using jquery and with the PHP code in that page run the mkdir that you want.
JS:
$.ajax({
url: 'test.php',
success: function(data) {
alert('Directory created');
}
});
test.php文件:
test.php FILE:
<?php mkdir('/test1/test2', 0777, true); ?>
这篇关于在jQuery单击中运行php函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文