Php AJAX在第一次单击时不起作用,需要单击两次

Php AJAX在第一次单击时不起作用,需要单击两次,php,jquery,ajax,unlink,Php,Jquery,Ajax,Unlink,更新: 现在的问题是,在使用firebug之后,我发现第一个元素获得了title属性,而其他元素没有。在任何链接上悬停后,第一个链接的title属性消失了,有什么想法吗 当我点击如下链接时,我有一个打开的页面: <a class="pictures" href="#" onClick="MM_openBrWindow('content_image.php','images','menubar=yes,scrollbars=yes,resizable=yes,width=650,height

更新:

现在的问题是,在使用firebug之后,我发现第一个元素获得了title属性,而其他元素没有。在任何链接上悬停后,第一个链接的title属性消失了,有什么想法吗

当我点击如下链接时,我有一个打开的页面:

<a class="pictures" href="#" onClick="MM_openBrWindow('content_image.php','images','menubar=yes,scrollbars=yes,resizable=yes,width=650,height=700')" title="Images"></a>
然后
取消链接()
图像。但是,只要我将鼠标悬停在链接上而不单击,图像就会被删除。我不知道为什么

我尝试使用AJAX来实现这一点:

$(document).ready(function(e) {
$("div.uploaded_image").on("click","a.del_img",function(e){
    e.preventDefault();
    var img = $(this).attr("title");
    var qst = "?img="+img+"&path=content_img";
    var ajax = false;
    ajax = new XMLHttpRequest();
    ajax.open("post","del_image.php"+qst);
    ajax.onreadystatechange = function(){
        if(ajax.readyState == 4 && ajax.status == 200){
        }
    }
    ajax.send(null);
    setTimeout(ref,1500);
});
});
function ref(){
window.location = "content_image.php"   
}
这段PHP代码使用AJAX删除:

$img = $_REQUEST['img'];
$path = $_REQUEST['path'];
unlink("../".$path."/".$img);
当我第一次点击删除链接时,它不起作用。我必须再次单击以删除图像。有什么帮助吗?

$open=opendir($path);
 $open = opendir($path);
while($images = readdir($open)){
    if ($images != "." && $images != "..") {
    $allimages[] = $images;
  } 
}
foreach($allimages as $val){
    ?>
     <div class="uploaded_image"><img src="../content_img/<?php echo $val; ?>" align='middle' width='150px' height='100px'>         
        <form><a href="Javascript:void(0);" title="<?php echo $val; ?>" class="del_img"><img src="images/delete.gif"/></a> <textarea name='text_area' rows=1 cols=20 >../content_img/<?php echo $val; ?></textarea> <input type='button' value='select path' onClick='javascript:this.form.text_area.focus();this.form.text_area.select();'> Copy path and paste in image path field </form></div>
        <?php
}
closedir($open);
?>         
而($images=readdir($open)){ 如果($images!=“&&&$images!=”){ $allimages[]=$images; } } foreach($val形式的所有图像){ ?> “对齐class='middle'宽度class='150px'高度class='100px'> ../content\u img/复制路径并粘贴到图像路径字段中
用此代码替换代码更改

$("div.uploaded_image").on("click","a.del_img",function(e){
    e.preventDefault();


在表单tag replace href=#with href=“Javascript:void(0);”下的标记中,我将属性化的“title”更改为“code”,并且成功了。我不知道为什么在
警报“something”;
之后
e.preventDefault();
之后以及
ajax.open(“post”,“del_image.php”+qst)之后,“title”属性消失了
第一次单击后,屏幕上是否会出现警报我将属性“title”更改为“code”,并且成功了我不知道为什么“title”属性会消失
 $open = opendir($path);
while($images = readdir($open)){
    if ($images != "." && $images != "..") {
    $allimages[] = $images;
  } 
}
foreach($allimages as $val){
    ?>
     <div class="uploaded_image"><img src="../content_img/<?php echo $val; ?>" align='middle' width='150px' height='100px'>         
        <form><a href="Javascript:void(0);" title="<?php echo $val; ?>" class="del_img"><img src="images/delete.gif"/></a> <textarea name='text_area' rows=1 cols=20 >../content_img/<?php echo $val; ?></textarea> <input type='button' value='select path' onClick='javascript:this.form.text_area.focus();this.form.text_area.select();'> Copy path and paste in image path field </form></div>
        <?php
}
closedir($open);
?>         
$("div.uploaded_image").on("click","a.del_img",function(e){
    e.preventDefault();
$("div.uploaded_image a").click(function(e){
    e.preventDefault();
...