Jump to content

FadeOut if php returns true


JonnySnip3r

Recommended Posts

Hey guys im new to jQuery so hope some one can help. I can manage to get the fading to work on an element, however i was wondering if someone could help me. I have a comments section with an icon when the user clicks the icon it deletes the post. Is there away that i can give some feedback to jquery and if the post deleted then the div will fade, and also to stop the page refreshing. So like asynchronously call a php script. Below is some code...

 

<a href='delete_member_comment.php?delete_id=$id'>
<img src='profile/icons/comment_delete.png' alt='Delete this Comment' title='Delete this Comment' />
</a>

 

and my delete script:

 

<?php

if(isset($_GET['delete_id'])){

	$post_to_delete = intval($_GET['delete_id']);

	if(!(intval($post_to_delete))){
		header("Location: index.php");
		exit();
	}else{

		require_once 'includes/config.php';
		$query = "DELETE FROM taggitt WHERE id='$post_to_delete'";

		if(!mysql_query($query)){
			header("Location: index.php?message=DeleteFailed");
			exit();
		}else{
			header("Location: index.php?message=DeleteSuccess");
			exit();
		}

	}

}else{
	header("Location: index.php");
	exit();
}



?>

 

maybe i could echo "success" and then it call the jquery script after im not sure new to jquery haha hope some one can help though!

 

Link to comment
Share on other sites

Well i managed to resolve the problem myself and incase anyone is left scratching their heads i will paste in the code below on how i did this.

 

$(function() {
$(".delbutton").click(function(){

//Save the link in a variable called element
var element = $(this);

//Find the id of the link that was clicked
var del_id = element.attr("id");

//Built a url to send
var info = 'id=' + del_id;
	if(confirm("Are you sure you want to remove this comment?")){

	$.ajax({
   	type: "POST",
   	url: "delete_member_comment.php",
   	data: info,
   	success: function(){
   	}
});

 

and the php side of things

 

<?php

session_start();

if(isset($_SESSION['authenticated'])){

	if(isset($_POST['id'])){

		$id = intval($_POST['id']);

		if(!intval($id)){
			return false;
			header("Location: index.php");
			exit();
		}else{

			require_once 'includes/config.php';
			$query = "DELETE FROM comments WHERE id = '$id'";

			if(!mysql_query($query)){
				return false;
				header("Location: index.php");
				exit();
			}else{
				return true;
			}
		}
	}else{
		header("Location: index.php");
		exit();
	}
}else{
	header("Location: index.php");
	exit();
}


?>

 

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.