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
https://forums.phpfreaks.com/topic/208411-fadeout-if-php-returns-true/
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();
}


?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.