Jump to content

Delete XML Node With jQuery.remove


hobbiton73

Recommended Posts

I wonder whether someone may be able to help me please.

 

I've put together this http://www.mapmyfinds.co.uk/development/deletetest.php page which allows users to view a gallery of their uploaded images.

 

Upon initial upload, the physical images are saved in the following file structure: UploadedFiles/userid/locationid/image and the details of the image i.e. description etc are saved in an xml file called 'files.xml' which is stored in the same directory as the physical images.

 

I'm now working on allowing the user to be able to delete these images.

 

By way of a deletion icon under each image, I've, admitedly with some 1st class help from scootstah on this forum, put together the following which successfully deletes the physical image.

 

'Onclick Event'

<script type="text/javascript"> 
	Galleria.ready(function() {
		this.$('thumblink').click();

	$(".galleria-image").append( 
	"<span class='btn-delete ui-icon ui-icon-trash'></span>"); 
	$(".btn-delete").live("click", function(){
	var img = $(this).closest(".galleria-image").find("img"); 

	// send the AJAX request
	$.ajax({
	url : 'delete.php',
	type : 'post',
	data : { image : img.attr('src') },
	success : function(){
	alert('Deleting image... ');
	img.parent().fadeOut('slow');
	}
	});

	return false;
	});

	});

</script>

 

delete.php

 

<?php

if (!empty($_POST)) {
$image = $_POST['image'];

if (file_exists($image)) {
unlink($image);
} 
}
?>

 

The problem I'm having, is deleting the matching node in my xml file, an extract of which can be found below:

 

<?xml version="1.0" encoding="utf-8" ?> 
- <files>
  <file name="stag.jpg" source="stag.jpg" size="21341" originalname="stag.jpg" description="No description provided" userid="1" locationid="1" /> 
  </files>

 

I've done quite a bit of research and found that the jQuery had a command call 'jQuery.remove'. Using a brief tutorial I found, I added the folowing to the end of my 'Onclick event' script.

 

var doc = $(files.xml); 
doc.find('file_name:src').remove(); 

 

Unfortunately, although I receive no error message, the row in my XML is not deleted, and I'm not really sure why.

 

I just wondered whether someone could have a look at this and let me know where I've gone wrong.

 

Many thanks and kind regards

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.