troubleshooting Question

Jquery/Ajax Success or Failure

Avatar of benners70
benners70 asked on
JavaScript
4 Comments2 Solutions730 ViewsLast Modified:
Hi. The page below includes Jquery which detects if a delete link is clicked and if so, it triggers the ajax to delete an image. I want to add a "hidden" class to the the parent DIV if the Ajax is successful but I don't know how to keep hold of the ID of the closest DIV after the Ajax success.

Can some help me add hidden class to parent DIV if successful and alert an error if not succesful?

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js?ver=3.1.2'></script></head>
<body>
<div class="pic_container">
  <div class="pic_item" id="1">
    <p><a href="#" class="delete" title="img1.jpg">Delete</a></p>
  </div>
</div>
<div class="pic_container">
  <div class="pic_item" id="2"><a href="#" class="delete" title="img2.jpg">Delete</a>
    </p>
  </div>
</div>
<script type="text/javascript">
	$('.delete').click(function(){
		var id = $(this).closest("div").attr("id");
		alert(id);
		var form_data = 
		{
			file_orig: 'data1',
			ajax: '1'
		};
		$.ajax({
			url: "ajax_process.php",
			type: 'POST',
			data: form_data,
			success: function(msg) {
				alert(msg);
				//$('#'+$id).addClass("hidden");
		}
	});
	return false;
});
</script>
</body>
</html>
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros