Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6385303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:52:57+00:00 2026-05-25T02:52:57+00:00

I am trying to use jquery ajax to delete some data specifically ingredients of

  • 0

I am trying to use jquery ajax to delete some data specifically ingredients of a recipe and I am using the CodeIgniter framework but it fails. Here is the parts of my code:

$(".delete").live('click',function()
{
 var ri_id = $(this).attr('id');
 if(confirm("Are you sure you want to delete this ingredient? Action cannot be undone."))
 { 
  var r_id = "<?php echo $this->uri->segment(3); ?>";
  alert(ri_id +" " +r_id); 
  $.ajax({
     type: "POST",
     url: "/ingredient/delete",
     data: "ri_id="+ri_id +"&r_id=" +r_id,
     success: function(){
      $(this).parent().parent().parent().remove();
     },
     failure : alert('fail')
  });

Then here is my ingredient.php:

class Ingredient extends CI_Controller {

    function delete()
    {
        $data['ri_id']= $this->input->post('ri_id');
        $data['r_id']= $this->input->post('r_id');

        if (!empty($data['id']))
        {
            $this->load->model('ingredient_model', '', TRUE);
            $this->ingredient_model->delete_recipe_ingr($data);
            $this->output->set_output('works');
        } 
        else 
        {
            $this->output->set_output('dontwork');
        }
    }

}

and my model:

  class Recipe_model extends CI_Model
  {
      public function delete_recipe_ingr($data)
      {
          $this->db->where($data);
          $this->db->delete('st_recipe_ingredients');  
      } 
  }

Did I miss something or is it my code that is wrong? I would really appreciate your help. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:52:58+00:00Added an answer on May 25, 2026 at 2:52 am

    My first guess is that this isn’t what you think it is right here:

    success: function(){
      $(this).parent().parent().parent().remove();
    },
    

    From the fine manual:

    context
    This object will be made the context of all Ajax-related callbacks. By default, the context is an object that represents the ajax settings used in the call ($.ajaxSettings merged with the settings passed to $.ajax).

    So inside your success callback, this is pretty much a simple object rather than something in the DOM.

    There are two standard solutions. You could save a reference to this and use that:

    var self = this;
    $.ajax({
        // ...
        success: function() {
            $(self).parent().parent().parent().remove();
        },
        // ...
    

    or use the context option to $.ajax:

    $.ajax({
        // ...
        context: this,
        success: function() {
            $(this).parent().parent().parent().remove();
        },
        // ...
    

    And, of course, fix up the failure stuff as discussed in the comments.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use Jquery.ajax() with PUT and DELETE methods and sending some
I'm trying to use jquery.Ajax to post data to an ASP.NET MVC2 action method
I am trying to use jQuery's ajax functionality to update data from a web
So I am trying to use jQuery to insert data from an ajax call.
I am using CakePHP 1.26 . I was trying to use jQuery Ajax to
EDITED I'm trying to use jquery/ajax to display data returned from a django method.
Ok so I know long hand ajax but trying to use the jQuery short
I'm trying to use jQuery and Ajax and I use this method. but I
I'm trying to use some jQuery code for Ajax which works well in Firefox
I'm trying to use jQuery to format code blocks, specifically to add a <pre>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.