JQuery AJAX-PHP mkdir() 问题
我一直在尝试让一个脚本能够使用 AJAX 将 PHP 文件调用到 jQuery 脚本中。
var dataString = 'Submit=Set';
$.ajax({
type: "POST",
url: "./inc/php/file.php",
dataType: "json",
data: dataString,
success: function(data) {
$('.error').html(data.errormsg+' OK.');
},
error: function(data) {
$('.error').html(data.errormsg+' OH NO.');
}
});
它正在调用 PHP 的这段代码,
$blogstatus =array();
$blogstatus['errormsg'] = 'NOTHING';
if(isset($_POST['Submit'])){
$blogstatus['errormsg'] = 'FIRST';
if (file_exists('/files/subfolder/')){
$blogstatus['errormsg'] = 'exists';
}else{
$blogstatus['errormsg'] = 'YES';
mkdir('./files/subfolder/',0777);
}
echo json_encode($blogstatus);
如果我将 mkdir 取出来,一切都会正常运行,我可以调用 errormsg。 我尝试在标准 PHP 脚本中运行 mkdir 而无需 ajax 调用,并且成功了。 每次我将 mkdir 放入脚本中时,我都会收到错误消息变量未定义并且脚本失败。
我对使用 jquery 相当陌生,所以这可能是我忽略的一些简单的东西。为任何帮助干杯
I've been trying to get a script to work that calls a PHP file into a jQuery script using AJAX.
var dataString = 'Submit=Set';
$.ajax({
type: "POST",
url: "./inc/php/file.php",
dataType: "json",
data: dataString,
success: function(data) {
$('.error').html(data.errormsg+' OK.');
},
error: function(data) {
$('.error').html(data.errormsg+' OH NO.');
}
});
and it's calling this bit of PHP
$blogstatus =array();
$blogstatus['errormsg'] = 'NOTHING';
if(isset($_POST['Submit'])){
$blogstatus['errormsg'] = 'FIRST';
if (file_exists('/files/subfolder/')){
$blogstatus['errormsg'] = 'exists';
}else{
$blogstatus['errormsg'] = 'YES';
mkdir('./files/subfolder/',0777);
}
echo json_encode($blogstatus);
If i take the mkdir out everything runs fine and i can call errormsg.
I've tried running the mkdir without the ajax call in a standard PHP script, and that worked.
Everytime i put the mkdir into the script i get the errormsg variable as undefined and the script fails.
Im fairly new to using jquery so it maybe something simple im over looking. cheers for any heelp
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请确保满足以下几点:
另外,从命令中删除尾部斜杠
Please make sure the following points are satisfied:
Also, remove the trailing slash from your command