SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with $.ajax function - cant delete items

    I have a number of items on a page, each has a delete <div id = "delete_question"></div>, when clicked it calls an $.ajax function to delete the selected item. For some reason it only works for the first item, if I try to delete the second item nothing happens - I am checking with Firebug and no action is sent by jquery...

    Code:
    $(function() {
    		var question_id = $('#question_id_hidden').val();
    				
    		$('#delete_question').click(function() {
      
                    $.ajax({
                        url: '<?php echo base_url();?>index.php/knowledge/delete',
    					type:"POST",
    					data:{'question_id':question_id},
                        success: function() {
    						window.location.reload(true)
                        } //end success
                    });
    
    		});
    });

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,191
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    The problem is your using an ID, for multiple instances of an action to work correctly you would need to use a class instead. Simply put change your pound/hash # to a period . and it will work correctly. However what does your question_id value refer to as referring to one ID isn't going to work as you would expect.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •