1

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

5
  • 1
    can you check what is the response of your ajax call? You can do that by either doing an alert(data) in the success function ... or else using firebug you can check the response of the request. Commented Jun 1, 2011 at 9:14
  • i call back the $blogstatus['errormsg'] when i run the script without the mkdir i get all results as i should do and i get YES back. when i put the mkdir back in $blogstatus['errormsg'] comes back as undefined and i get OH NO Commented Jun 1, 2011 at 9:22
  • a ran the alert(data) and it came back with [object Object]. What does this mean? Commented Jun 1, 2011 at 9:37
  • youtube.com/watch?v=W4jXAaEMp2M watch this video it will explain to you how to debug an ajax request. Commented Jun 1, 2011 at 9:39
  • once you manage to read the response of your ajax call paste in your answer so we can help you :) Commented Jun 1, 2011 at 9:44

1 Answer 1

2

Please make sure the following points are satisfied:

Make sure the parent folder has the permission for apache to run your command?

Also, remove the trailing slash from your command

mkdir('./files/subfolder/',0777);

to

mkdir('./files/subfolder',0777);
- it is good to supply the full path when it comes to linux commands. For ex:

mkdir('/var/www/html/someproject/somemodule/files/subfolder',0777);
Sign up to request clarification or add additional context in comments.

2 Comments

Yea that did it cheers. Just for future reference is there a way of making a variable accessible from any on the site to make the path writing quicker? Im guessing something like var pathname = 'path/a/b/c' but u never no
If you want this just for a PATH and if it is inside the public folder then use $_SERVER["DOCUMENT_ROOT"]. Otherwise I would suggest you to write a Commonlibs.php and dump all common functions. For ex: getImagePath(); or getLibraryPath(); etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.