Jump to content

need help with this ajax function


yami007

Recommended Posts

well, i found this function somewhere on the web, it actually works but i hope i can get the output ( success/error ) to tell the user what happened !

 

the ajax function :

 

<script type="text/javascript" language="javascript">
	<!--
	function deleteNotification(yourimportedString) {

		url = "delete_notification.php?id=" + yourimportedString
		if (window.XMLHttpRequest) { // Non-IE browsers
		  req = new XMLHttpRequest();
		  req.onreadystatechange = targetDiv;
		  try {
			req.open("GET", url, true);
		  } catch (e) {
			alert(e);
		  }
		  req.send(null);
		} else if (window.ActiveXObject) { // IE
		  req = new ActiveXObject("Microsoft.XMLHTTP");
		  if (req) {
			req.onreadystatechange = targetDiv;
			req.open("GET", url, true);
			req.send();
		  }
		}

		//alert('javascript is working fine !')
	}

	function targetDiv() {
		if (req.readyState == 4) { // Complete
			  if (req.status == 200) { // OK response
				  document.getElementById("MyDivName").innerHTML = req.responseText;
			  } else {
				alert("Problem: " + req.statusText);
			  }
		}
	}
	-->
</script>

 

the php code on the delete_notification.php is as follows :

 

<?php 
if(isset($_GET['id'])) {

	$id = $_GET['id'];

	$sql = "DELETE FROM notifications_user WHERE user_id='{$id}' LIMIT 1";
	$query = mysql_query($sql);

	if($query) {
		$message = 'user has been deleted succesfully !<br/>';
	} else {
		$message = 'user could not be deleted !<br/>';
	}

}

if($message) {
	echo '<p>'.$message.'</p>';
}
?>

 

so I want the variable $message to be got by  the function,

i'm not so well at javascript, so i have no clue :s:s

 

 

i hope i get some help :)

thanks !!

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.