Jump to content

Pass PHP/MYSQL values to ajax on click


rx3mer
Go to solution Solved by 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
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

Edited by gristoi
Link to comment
Share on other sites

I don't think that you understand my question, or I just don't understand your answer. I know how to make the function run on click. The problem I am having is that I don't know how to pass the values to the ajax as data.

 

Any ideas?

Link to comment
Share on other sites

  • Solution

gristoi it worked after some testing. Basically what I was getting wrong was the id name on my div element.

 

<div class="delete_class delete" ID="<?php echo $info['PlaylistSongID']; ?>">Delete</div>

 

Thank you very much!

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.