www.webdeveloper.com
Results 1 to 2 of 2

Thread: help with ajax image delete...

  1. #1
    Join Date
    Dec 2005
    Posts
    193

    help with ajax image delete...

    I found a script online for uploading images with ajax. it all works fine, I can upload and save images to the database. I have some rudimentary php knowledge, javascript i am completely lost... at any rate here is what I have:

    Code:
    				if(response!="error" && response!=""){
    
    					$('<li></li>').appendTo('#files').html('<img src="+response+" border="0" alt="" /><br />').addClass('success');
    				} else{
    					$('<li></li>').appendTo('#files').text(file).addClass('error');
    				}
    so I was thinking something like this:

    Code:
    				if(response!="error" && response!=""){
    				Number++;
    					$('<li></li>').appendTo('#files').html('<img src="+response+" border="0" alt="" /><a name="#" onclick="dev(Number)">remove</a><br />').addClass('+Number+');
    				} else{
    					$('<li></li>').appendTo('#files').text(file).addClass('error');
    				}
    is that correct so far? count the number of images and add the number to the class, then delete by the class? should i use ID? does addId work like add class? .. oh and i could use the count Number to limit the number of uploads too??

    next how would i fire off my onclick? i'm so lost with javascript...

  2. #2
    Join Date
    Dec 2005
    Posts
    193
    I am so lost... I am trying to upload a file, save it to the database, return the database count of images and the image url.
    all that is working.
    then I want to remove it if remove is clicked. I can hide the image with JavaScript but the <li> container remains. I think I will also need to return from the first ajax call the insert id. no problem.

    but how do i use that returned insert id to trigger a second ajax call to delete that file if asked? here is what I have so far... I'm really lost here..

    Code:
    				var myString = response;
    				var mySplitResult = myString.split("_8_");
    				if(mySplitResult[0]=="1"){
    					$('<li></li>').appendTo('#files').html('<img src="'+mySplitResult[1]+'" border="0" alt="" id="'+mySplitResult[0]+'"style=""/><br /><a name="#" onclick="fileR('+mySplitResult[0]+')">remove</a>').addClass('success');
    					}
    				
    				if(mySplitResult[0]=="2"){
    					$('<li></li>').appendTo('#files').html('<img src="'+mySplitResult[1]+'" border="0" alt="" id="'+mySplitResult[0]+'"style=""/><br /><a name="#" onclick="fileR('+mySplitResult[0]+')">remove</a>');
    					document.getElementById("upload").style.display = "none";
    					}				
    				} else{
    					$('<li></li>').appendTo('#files').text(file).addClass('error');
    				}
    			}
    		});
    		
    	});
    	
    	
    function fileR(numID)
    {
    var theID = numID;
    $('<li></li>').document.getElementById(theID).remove('#files');
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles