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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:54:12+00:00 2026-06-09T03:54:12+00:00

Im using cakePHP 2.2.1 I have a GoalsController that has an add action in

  • 0

Im using cakePHP 2.2.1

I have a GoalsController that has an add action in it. This action saves posted data to Goals table.

Inside the add.ctp im using jQuery ajax method to post the form data to above said add action.

What i want is,

  1. ajax method posts form data to goals/add
  2. goals/add action saves data to goals table
  3. Obtain the id of newly inserted row using $this->Goal->id
  4. Return this id back to the onSuccess function of ajax method

Steps 1,2,3 are working fine. But i dont know how to implement step4.

I know php is server side and js is client side and all. Is there anyway i can achieve this?

  • 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-09T03:54:13+00:00Added an answer on June 9, 2026 at 3:54 am

    Be sure to read the book entry on Json views and implement something like this:

    // Routes.php
    Router::parseExtensions('json');
    
    // Controller
    $this->set('id', $this->Goal->id);
    $this->set('_serialize', array('id'));
    
    // AppController.php
    public $components = array('RequestHandler'); // Or add 'RequestHandler' to the existing list.
    

    Then you need to make your ajax post to /goals/add.json, Cake will then recognise the .json extension in combination with the $this->set('_serialize') and return a json string along the lines of { id: 1 }.

    Then in your $.ajax function, have a success call like this:

    $.ajax({
        url: '/goals/add.json',
        dataType: 'json'
        // other settings
        success: function(response) {
            alert(response.id); // response contains the returned data
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im using cakephp 2.0 and i have data submitted that i want to cleanup,
This site is built using CakePHP 1.2* I have an element that needs to
I have created a temporary table using cakephp $this->Model->query() and inserted some records using
I am using cakephp with php, I have table with field id having data
Using CakePHP 1.3 , I have a (working) form that has dynamically created form
I have a web application that has been done using Cakephp with MySql as
I'm using cakephp 2.1.3 and I have a table Ingredients and a table IngredientAliases
Using cakephp, I have a generic address table, which I want to link to
I am using cakephp 1.2 and I have an array that appears to have
I have trouble saving my date field into database using CakePHP. Table column name

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.