yami007 Posted January 6, 2010 Share Posted January 6, 2010 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 https://forums.phpfreaks.com/topic/187422-need-help-with-this-ajax-function/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.