• Hi all!

    I have a little problem.
    I’m developing a plugin, where I can add an URL and a name to my database, and it works perfectly.

    Now, I put all my information in a table, and it works like a charm too!
    Every URL has a “Delete” button, and here’s where it goes wrong!

    When I press the “Delete” button, it ONLY WORKS if I press the newest URL – if I press nr. 2 or nr. 3 on the list, it’s not working??

    Here’s my code for the “Delete” button/form:

    <div id="wcommentreminder_deleteform">
        <form action="" id="wcommentreminder-deleteform" method="POST">
        <input type="hidden" id="wcommentreminderdel" name="wcommentreminderdel" value="<?php echo $print->id; ?>">
        <?php wp_nonce_field('comment_delete_nonce') ?>
        <input type="submit" class="button-primary" name="comment_delete" value="Delete" />
        </form>
        </div>

    And here’s my jQuery/AJAX:

    jQuery(document).ready(function($) {
    	 $('#wcommentreminder-deleteform').submit(function() {
    
    		 var data = {
    			 action: 'wcommentreminder-deleteaction',
    			 name: document.getElementById("wcommentreminderdel").value,
    			 securitydel: document.getElementById("_wpnonce").value
    		 };
    
    		 $.post(ajaxurl, data, function(response) {
    			alert('Works!');
    		 });
    
    		 return false;
    	 });
    });

    And just to make sure you have it all, here’s my “action”:

    add_action('wp_ajax_wcommentreminder-deleteaction','wcommentreminder_form_delete');
    
    function wcommentreminder_form_delete() {
    	global $wpdb;
    
    	$table_name = $wpdb->prefix . "wcommentreminder";
    
    	$id = $_POST['name'];
    
    	if (!wp_verify_nonce($_POST['securitydel'],'comment_reminder_field_nonce') ) { wp_die('Oops, your nonce didn\'t verify. So there.'); }
    
    	$wpdb->query("DELETE FROM $table_name WHERE id = '$id'") or wp_die(mysql_error());
    
    	if($wpdb){
    	echo "<div class='updated'>The URL was deleted! <a href='' onClick='window.location.reload()'>Add another one?</a></div>";
    	} else {
    	echo "Error, try again later.";
    	}
    
    	die();
    
    }

    Can anyone see whats wrong here?
    Why is it, only the first “Delete” button that works???
    Help!

    Thank you in advance
    Aris Kuckovic

    [Moderator Note: No bumping, thank you.]

  • The topic ‘AJAX only deletes newest URL’ is closed to new replies.