Solved

JQuery function calling itself to reload issue

Posted on 2010-11-22
3
774 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
Comment Utility
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
Comment Utility
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
Comment Utility
thanks for the help, great idea!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now