Reputation: 129
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?
Upvotes: 0
Views: 62
Reputation: 1593
Try to add
del.setRequestHeader("Content-type","application/x-www-form-urlencoded");
before del.send()
.
Upvotes: 1