我正在使用以下php
代码在xampp
服务器上创建文件夹和子文件夹......
<?php
$userFolder = "poop";
mkdir($userFolder);
$newfolder = $userFolder . "/bla bla bla";
mkdir($newfolder, 0777);
// check to see if it has been created or not using is_dir
if (is_dir($newfolder)) {
echo "The $newfolder directory has been created<br /><br />";
}
?>
我的问题是我如何使用ajax来做这个......任何帮助都会受到赞赏... :)提前感谢... :))
答案 0 :(得分:1)
假设您的文件是dir.php
<?php
$userFolder = "poop";
mkdir($userFolder);
$newfolder = $userFolder . "/bla bla bla";
mkdir($newfolder, 0777);
// check to see if it has been created or not using is_dir
if (is_dir($newfolder)) {
echo "The $newfolder directory has been created<br /><br />";
}
?>
您可以使用jquery来调用它
$.ajax({
url: "dir.php",
context: document.body
}).done(function() {
//sucesss response here
});
答案 1 :(得分:1)
使用jQuery库(这里简洁使用它),只需:
$.ajax({
method: 'POST',
url: 'path/to/your/php/file.php',
data: {folderName: 'someFolderName'},
success: function(data) {
console.log(data); //"The directory has been created."
}
});
并在你的php中:
$userFolder = $_POST['folderName'];
jQuery不是必需的。编写的代码更少。对于普通javascript,see here (click)。