Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

JQuery function calling itself to reload issue

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

860 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