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 7784849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:09:40+00:00 2026-06-01T20:09:40+00:00

I am trying to delete the element with post jquery request: $(function(){ //The element

  • 0

I am trying to delete the element with post jquery request:

$(function(){
    //The element
   // <a data-id="39" data-toggle="modal" href="#delete"><i class="icon-trash"></i> 

Delete</a>


   $('.delete').on('click',function(){
       var id= $(this).attr('data-id');


  $.post('task/delete',  { id: id }, function(data) {
        alert('Task deleted!');
    })
    .success(function(){  alert('Task deleted!'); })          
     .complete(function(){  alert('Task completed!'); })
     .error(function(){   alert('Error was found!'); });
   })

});

My controller is called task and the function inside it is called delete.

  class Task extends CI_Controller {

        public function delete()
    {
        $this->load->model('tasks_model','task_delete');
        $this->task_delete-> deleteTask($_POST['id']);

    }
     }

The model is quite simple.. it simply deletes the record.

    public function deleteTask($task_id)
    {
        $task_id = mysql_real_escape_string($task_id);
        $this->db->query("DELETE FROM tasks WHERE task_id = ?", array($task_id));

    }

I get two messages..one is error and one is delete…
Another thing that I want to avoid is someone posting the id to the controller task .. which will delete the records one by one automatically, is there a way to avoid this too?

  • 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-06-01T20:09:40+00:00Added an answer on June 1, 2026 at 8:09 pm

    Your controller method should look something like this

    public function delete()
    {
       // Do user validation here
      $this->load->model('tasks_model');
      $this->tasks_model->task_delete($this->input->post('id'));
      return "task deleted";
    }
    

    And you models method like this

    public function task_delete($task_id)
    {
      $this->db->where('task_id', $task_id);
      $this->db->delete('tasks');
    }
    

    As I would recommend validating the user where the comment says you should, and using CI’s active record library where you can to increase portability to a different DB.

    Edit

    To show PHP errors (and maybe MySQL errors if they are turned on).

    error_reporting(E_ALL);
    

    To ensure the task is deleted, do this (which is not as efficient).

    public function task_delete($task_id)
    {
      $this->db->where('task_id', $task_id);
      $this->db->delete('tasks');
    
      $this->db->from('tasks');
      $this->db->where('task_id', $task_id);
    
      $query = $this->db->get();
    
      if ( $query->num_rows() > 0 )
      {
        return FALSE;
      } 
      else return TRUE;
    }
    

    And then do something with the returned boolean in the controller.

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

Sidebar

Related Questions

I have this js code to add (clone) and delete an element. $('#btnAdd1').click(function (event)
I'm trying to delete a blog post on blogger.com using Blogger API via Prototype
I am trying to delete all specific key element in my linked list in
I am trying to initiate a click event for multiple instances of an element
I'm trying to delete the whole content of an RootPanel element based on an
Hi im trying call this function from an element, but the element id is
I'm trying to advance the Jquery-autcomplete function. I want Jquery-autocomplete to create new rows
I am trying to delete an element on a specific match between the value
I am trying to delete the child element in the dom from its parent
I'm trying to delete a li item using jquery, but its not working. Here's

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.