Javascript jquery删除文件并引用一个div
嗨,我是jquery新手,我想在服务器中删除一个文件并在div中刷新,但发生了一些错误 图像文件夹为../img/tanda_tangan/tanda_tangan.png 阿贾克斯 还有一个按钮Javascript jquery删除文件并引用一个div,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,嗨,我是jquery新手,我想在服务器中删除一个文件并在div中刷新,但发生了一些错误 图像文件夹为../img/tanda_tangan/tanda_tangan.png 阿贾克斯 还有一个按钮 <button type="button" id="hapus" class="hapus" > <span class="glyphicon glyphicon-remove"></span> </button> removefile.php
<button type="button" id="hapus" class="hapus" >
<span class="glyphicon glyphicon-remove"></span>
</button>
removefile.php
<?php
$path = $_POST['path'];
$return_text = 0;
// Check file exist or not
if( file_exists($path) ){
// Remove file
// unlink($path);
// Set status
$return_text = 1;
}else{
// Set status
$return_text = 0;
}
echo $return_text;
和一个div
<div id="tanda"></div>
怎么了?我无法删除文件
在../img/tanda_tangan/tanda_tangan.php中
var imgElement_src = $('../img/tanda_tangan/tanda_tangan.png');
// AJAX request
$.ajax({
url: 'removefile.php',
type: 'post',
data: {path: imgElement_src},
success: function(response){
// Changing image source when remove
if(response == 1){
$("#tanda").load(location.href + "#tanda");
}
}
});
我认为问题出在这方面
var imgElement_src = $('../img/tanda_tangan/tanda_tangan.png');
及
它应该是一个字符串,并确保路径正确。imgElement_src实际上是一个jquery对象,您希望在removefile.php中有一个路径字符串
<?php
$path = $_POST['path'];
$return_text = 0;
// Check file exist or not
if( file_exists($path) ){
// Remove file
// unlink($path);
// Set status
$return_text = 1;
}else{
// Set status
$return_text = 0;
}
echo $return_text;
希望它能帮助你解决一些错误发生了什么错误?删除功能不工作你能提供控制台的输出吗?您是否可以提供关于“网络”选项卡中的请求和响应?您已经对删除文件unlink$path的代码进行了注释@riyantonugrohoThis是一个对象变量imgElement_src=$'../img/tanda_tangan/tanda_tangan.png';不是字符串路径,请删除JQUERY包装器:var imgElement_src='../img/tanda_tangan/tanda_tangan.png';
data: {path: imgElement_src},