php - AJAX is not working on the first click, needs to be clicked twice -


update :

the problem after using firebug found out first element gets title attribute , other elements don't , after hovering on link title attribute of first link disappears ideas?

i have page opens when click on link this:

<a class="pictures" href="#" onclick="mm_openbrwindow('content_image.php','images','menubar=yes,scrollbars=yes,resizable=yes,width=650,height=700')" title="images"></a> 

this page has images stored in folder:

    $open = opendir($path); while($images = readdir($open)){     if ($images != "." && $images != "..") {     $allimages[] = $images;   }  } foreach($allimages $val){     ?>      <div class="uploaded_image"><img src="../content_img/<?php echo $val; ?>" align='middle' width='150px' height='100px'>                  <form><a href="#" 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 , paste in image path field </form></div>         <?php } closedir($open); ?>          

i trying delete images using regular link href page following attributes:

?do=delete&img=<?php echo $val; ?> 

and unlink() image. however, image deleted hover on link without clicking. don't know why.

i tried using 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"    } 

and php code work uses ajax delete:

$img = $_request['img']; $path = $_request['path']; unlink("../".$path."/".$img); 

when click on delete link first time doesn't work. have click again delete image. please?

 $open = opendir($path); while($images = readdir($open)){     if ($images != "." && $images != "..") {     $allimages[] = $images;   }  } foreach($allimages $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 , paste in image path field </form></div>         <?php } closedir($open); ?>          

replace code code


Comments