0

Hi guys I'm trying to delete a file with Ajax and I have this code:

functions.js:

function deleter(val){
var value = val.replace(".",",");
var del = new XMLHttpRequest();
del.addEventListener("load", completedelete, false);
del.open("POST","index.php?action=delete",true);
del.send("file="+value);
}

index.php:

if(isset($_REQUEST['action'])&& $_REQUEST['action']=="delete"){
if(!isset($_POST['file'])){
    echo("not set");
}
if(unlink($_POST['file'])){
    echo"1";
}else{
    echo"0";
}
}

and I always get "not set" in the response with the 0 .

any one can help me?

2
  • 1
    DANGER you are in dire need of some sanity checking on that input! What if someone submitted file=index.php? Commented Sep 23, 2013 at 22:32
  • don't worry man i got it handled this was just an example Commented Sep 24, 2013 at 8:50

1 Answer 1

1

Try to add

del.setRequestHeader("Content-type","application/x-www-form-urlencoded");

before del.send().

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.