Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Friday, October 7, 2016

Action Button to AJAX request in php

Action Button to AJAX request in php


How can i hide notification with ajax? I want to press button and pass to delete my notification with id 5.

if(isset($_POST['notification']))  {    $id = $_GET['hidenotification'];    $QUERY = "UPDATE `Notifications` SET `ActiveNotification` = 0 WHERE `id` = '$id'";    $connection->query($QUERY);  }  

$notification_id = 5;

Hide this notification    function HideNotification(id)  {   jQuery.ajax({    type: "POST",    url: "index.php",    data: 'hidenotification='+id,    cache: false,    success: function(response)      {        alert("Notification deleted.");      }   });  }  

My problem is when i press button to request hiding notification, my table is not updated ..

Answer by Martin Gottweis for Action Button to AJAX request in php


You can just hide it with Jquery's hide function:

Hide this notification    function HideNotification(id)  {      jQuery.ajax({          type: "POST",          url: "index.php",          data: 'hidenotification='+id,          cache: false,          success: function(response)          {              $('.notification').hide()          }      });  }  

Answer by Pradyut Manna for Action Button to AJAX request in php


function HideNotification(id)  {  jQuery.ajax({  type: "POST",  url: "index.php",  data: {hidenotification:id},  cache: false,  success: function(response)  {    alert("Notification deleted.");  }  });  }  

Answer by Omprakash Patel for Action Button to AJAX request in php


You can use following code for hide notification and update in database table via ajax php. And use $_REQUEST OR $_POST if you used post method in ajax.

Hide this notification      function HideNotification(id)  {  jQuery.ajax({  type: "POST",  url: "index.php",  data: {hidenotification:id},  cache: false,  success: function(response)  {  jQuery('#'+id).hide();  }  });  }  

Answer by Nikhil Vaghla for Action Button to AJAX request in php


Simply If you want to hide your button after response get.

try bellow code...

Html code

$notification_id = 5;    Hide this notification  

Jquery code

$(".notification").click(function(){      var obj=$(this);      jQuery.ajax({          type: "POST",          url: "index.php",          data: {hidenotification: obj.attr('id')},          cache: false,          success: function(response)          {             obj.hide()// if you want to only hide button             obj.remove() //if you want to remove button          }      });  });  

Php code

if(isset($_POST['hidenotification']))  {    $id = $_POST['hidenotification'];    $QUERY = "UPDATE `Notifications` SET `ActiveNotification` = 0 WHERE `id` = '$id'";    $connection->query($QUERY);  }  

Answer by Shaunak for Action Button to AJAX request in php


just keep

$id = $_POST['hidenotification'];    $QUERY = "UPDATE `Notifications` SET `ActiveNotification` = 0 WHERE `id` = '$id'";    $connection->query($QUERY);  

instead.Remove if(isset($_POST['notification'])) and use post.


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.