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

The Archive Base Latest Questions

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

I’m trying to build a system where I can submit data to a database

  • 0

I’m trying to build a system where I can submit data to a database using AJAX. I can do this, and it works really well.

However, I’m struggling to do a similar thing when trying to delete a record. I am new to using Ajax, especially with CakePHP, and I’m finding the whole concept quite overwhelming. I can delete a record using just pure HTML, passing the ID to the controller and then redirecting to the original page. It is just the Ajax thing I’m struggling with, and obviously using Ajax would be a huge benefit.

This is the code I have in my view:

    <table>
        <tr>
            <th>ID</th>
            <th>Title</th>
            <th>Content</th>
            <th>&nbsp;</th>
        </tr>
        <?php foreach ($testing as $test) { ?>
            <tr>
                <td><?php echo $test['Testtable']['id']; ?></td>
                <td><?php echo $test['Testtable']['title']; ?></td>
                <td><?php echo $test['Testtable']['content']; ?></td>
                <td><?php echo $this->Html->link('Delete', array('controller' => 'testing', 'action'=>'delete_ajax_data', $test['Testtable']['id']), null, 'Are you sure?' );?></td>
            </tr>
        <?php } ?>
    </table>

And this is the code I have in my controller:

function delete_ajax_data($id) {
    $this->autoRender = false;
    $this->layout = 'ajax';

    $this->loadModel('Testtable');

    $this->Testtable->delete($id);
    $this->redirect('/test-area/');
}

And this is the code I have so far for my Ajax:

$(document).ready(function(){

    $('a.confirm_delete').click(function(event){
        event.preventDefault();

        $.ajax({
            url:'/testing/delete_ajax_data',
            type:'POST',
            data: $("a").attr("href").serialize()

        });     
    });

});

Cheers for any help with this, it is starting to stress me out!

EDIT: The code I used was wrong, and I have included the correct code now. Still not working though!

  • 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-01T23:09:44+00:00Added an answer on June 1, 2026 at 11:09 pm

    I’ve figured it out. I had several problems in the code.

    The first part was in the view. Instead of using CakePHP’s link builder I used a HTML link instead:

    <td><a href="id=<?php echo $test['Testtable']['id']; ?>" class="deleteajax">Delete</td>
    

    Then, for the Ajax, I used the following code:

    $('a.deleteajax').click(function(event){
    event.preventDefault();
    
    var answer = confirm("Delete this record?")
    if (answer){
        $.ajax({
            url:'/testing/delete_ajax_data/',
            type:'GET',
            data: $(this).attr("href")
    
        });
    }
    
    return false;  
    });
    

    The new Ajax code uses GET instead of POST, which returns the ID of the record I’m deleting as an ID variable which can then be used in the controller like this:

    function delete_ajax_data() {
        $this->autoRender = false;
        $this->layout = 'ajax';
    
        $id = $_GET['id'];
    
        $this->loadModel('Testtable');
    
        $this->Testtable->delete($id);
    }
    

    There is probably a better way to do this than what I’ve done, but for what I’m doing this works superbly.

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.