Solved

JQuery function calling itself to reload issue

Posted on 2010-11-22
3
779 Views
Last Modified: 2012-05-10
Hello,

I have the below JQuery setup that I'm trying to use.  The loadGallery function gets called when the page loads and loads some images with a link to delete the image (only link is in the code below).  When I click the deleteImage link, the deleteImage function gets call and the post to deleteImage.php delete's the image from the database, but then I need to reload the images on the page, so I call the loadGallery function, but the post to images.php never gets executed as I've put alerts before and after it and only the alert prior shows.  Any ideas?
$(document).ready(function(){
function loadGallery(albumId, albumTitle){	
$.post("images.php",{albumId:albumId},function(theXML){
	$('image',theXML).each(function(i){    
		var deleteLinkText = $(document.createTextNode("Delete"));
		var deleteLink= $(document.createElement("a"))
			.attr("class", "adminDelete")
			.attr("href", "")
			.attr("alt", id)
			.append(deleteLinkText )
			.click(function(){
				deleteImage(id, "image", "Delete Image Permanently?", albumId, albumTitle);	
				loadGallery(albumId, albumTitle);				
			});
		}		
	}
} 
function deleteImage(imageId, type, msg, albumId, albumTitle) {
	if (confirm(msg)){ 
		$.post("deleteImage.php", {imageId:imageId});			
	}
}    
}

Open in new window

0
Comment
Question by:cgray1223
3 Comments
 
LVL 3

Expert Comment

by:boraganesh
ID: 34186290
once you call post function...means your going to another page....its not going to excute any other things as control goes to another page.

.click(function(){
                        deleteImage(id, "image", "Delete Image Permanently?", albumId, albumTitle);      
                        loadGallery(albumId, albumTitle);                        
                  });


if (confirm(msg)){
           $.post("deleteImage.php", {imageId:imageId});                  
      }

its never calling loadGallery as function deleteImage taking cotrol to another page deleteImage.php.

you can do one thing..from deleteImage.php once you done with your work..deleting images you can call the previous page agan.

or

you can use the ajax to call the deleteImage.php thats the only solution am seeing



0
 
LVL 16

Accepted Solution

by:
jmatix earned 500 total points
ID: 34190621
Add a success handler to your $.post("deleteImage.php") and call loadGallery() from that as:


function deleteImage(imageId, type, msg, albumId, albumTitle) {
 if (confirm(msg)){ 
  $.post("deleteImage.php", {imageId:imageId}, function(){loadGallery(albumId, albumTitle);});			
 }
}

Open in new window

0
 

Author Closing Comment

by:cgray1223
ID: 34193695
thanks for the help, great idea!
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question