Solved

JQuery function calling itself to reload issue

Posted on 2010-11-22
3
776 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

920 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

12 Experts available now in Live!

Get 1:1 Help Now