Jump to content

Pass PHP/MYSQL values to ajax on click


rx3mer

Recommended Posts

Hi guys,

 

I am trying to delete DB row without page refresh. I am aware of how to delete by passing URL values and I am trying to do the same thing, but with AJAX.

 

image.jpg

		 $data = mysql_query("SELECT * FROM playlistsongs WHERE PlayList = '$playlistsongid'") or die(mysql_error()); 
		 while($info = mysql_fetch_array( $data )) { ?>

		<?php 
			<table border="1px">
		 	<tr>
				<td style="width: 100px;"><?php echo "<b>PlaylistSongID:</b> ".$info['PlaylistSongID'];?></td>
				<td style="width: 100px;"><?php echo "<b>PlayList:</b> ".$info['PlayList'];?></td>
				<td style="width: 100px;"><?php echo "<b>UserID:</b> ".$info['UserID'];?></td>
				<td style="width: 100px;"><?php echo "<b>SongUrl:</b> ".$info['SongUrl'];?></td>
				<td style="width: 100px;"><?php echo "<b>Status:</b> ".$info['Status'];?></td>
				<td style="width: 100px;"><?php echo "<b>DateCreated:</b> ".$info['DateCreated'];?></td>
				<td style="width: 100px;"><?php echo "<b>DateModified:</b> ".$info['DateModified'];?></td>
				<td style="width: 100px;"><?php echo "<b>Artist:</b> ".$info['Artist'];?></td>
				<td style="width: 100px;"><?php echo "<b>Title:</b> ".$info['Title'];?></td>
				<td style="width: 100px;"><a data-customer-id="345" class="button remove">Remove</a></td>
				</td>
			</tr>
		</table>

And this is my AJAX request:

function DeletePlayListItem(){

  $.ajax({
   'url': 'processing/delete-playlist-items.php',
   'async': false,
    data: "PlaylistSongID=" + PlaylistSongVarID + "&UserID=" +  UserVarID + "&Status=", 
    success: function (response) {

        var posturl='http://localhost/xampp/websites/Djapp/processing/delete-playlist-items.php'
        
        $.getJSON(posturl,function(data){
          $.each(data.members, function(i,userdetails){
            takeuserid = (userdetails.UserID);
            title = (userdetails.Title);
            vote1 = (userdetails.Vote1);
          });
        });
    }
  });

}

So my question is, how do I pass the values to the AJAX on click/select?

Thank you for your time!

 

 

Link to comment
https://forums.phpfreaks.com/topic/287101-pass-phpmysql-values-to-ajax-on-click/
Share on other sites

you need to listen to the click event of the remove button. something like this:

$('.remove').click(function(e){
  e.preventDefault();
  var me = $(this);
  var customer-id = me.data('customer-id');
  $.ajax({
   'url': 'processing/delete-playlist-items.php',
   'async': false,
    data: {
       customer-id: customer-id

     }, 
    success: function (response) {
 
        // use something like  me.getParent('td').fadeOut(); or something similar to remove the row
    }
  });

});

it would be a lot easier for the scope of the event if you added the data attributes you want to send to the anchor, then you can implement what i put there for you :). hope it helps

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.