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

  • Home
  • SEARCH
  • 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 4098388
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:17:44+00:00 2026-05-20T20:17:44+00:00

I’m working with CakePHP 1.3.7 and I’m trying to do the following: On a

  • 0

I’m working with CakePHP 1.3.7 and I’m trying to do the following:

On a given page, the user can click a link (or image, or button, doesn’t matter) that passes a parameter which is saved into a database. BUT, all this, without refreshing the page.

I’ve been doing some research and I believe I need to use AJAX as well to acomplish this. However, I can’t find the a good example/explanation on how to do it.

I think that the idea is to create the link using AJAX, which calls the controller/action that would receive the variable as a parameter and performs the operation to save it in its corresponding field/table of the DB.

Does anyone have a small example of what I want to do? Or maybe point me to some tutorial that explains it… Thanks so much in advance!

EDIT

Well, thank you guys for your replies. THey’re not working directly, but I think I’m getting closer to what I want. Here’s what i’m doing now:

I have this code in my view:

<div id="prev"><a>click me</a></div>

<div id="message_board"> </div>

I call this JS file:

$(document).ready(function () {

$("#prev").click(function(event) {      
    $.ajax({data:{name:"John",id:"100"}, dataType:"html", success:function (data, textStatus) {$("#message_board").html(data);}, type:"post", url:"\/galleries\/add"});
    return false;
});
});

And my add action in my galleries controller looks like:

function add() {

    $this->autoRender = false;  

    if($this->RequestHandler->isAjax()) {

    echo "<h2>Hello</h2>";
    print_r($this->data);
        $this->layout = 'ajax';

        if(!empty($this->data)) {

    $fields = array('phone' => 8, 'modified' => false);
        $this->User->id = 6;
            $this->User->save($fields, false, array('phone'));

        }
}
}

When clicking on the ‘#prev’ element, I get a response from the add action, I know because the text ‘Hello’ is printed inside #message_board. And it does this without refreshing the page, which is why I need. My problem is that I can’t make the $.ajax() function to send any data, when it gets to the controller the $this->data is empty, so it never goes inside the if that saves the info to the database (right now it’s saving just an easy thing, but I will want it to save the data that comes from the view).

Can anyone see what am I doing wrong? How can I send the data to the controller?

  • 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-20T20:17:44+00:00Added an answer on May 20, 2026 at 8:17 pm

    CakePHP does not matter, most of the code you would need for this would be at clientside. Implementing AJAX by yourself is a pain in the $, so you really want to use a library; currently the most popular is probably jQuery. There’s a bunch of examples on their AJAX page: http://api.jquery.com/jQuery.ajax/

    So, assuming you have something like this in the document:

    <form id="s">
      <input id="q"/>
      <input type="submit" href="Search!"/>
    </form>
    <div id="r"/>
    

    you can put this in the JavaScript:

    $('#s').submit(function(evt) {
      evt.preventDefault();
      $.ajax({
        url: 'foo.php',
        data: {
            query: $('#q').val()
          },
        success: function(data) {
            $('#r').html(data);
          }
      });
      return false;
    });
    

    Then your foo.php only needs to return the fragment HTML that would go into the div#r.

    EDIT: I forgot to stop the submit 🙁 Thanks to @Leo for the correction.

    EDIT: I can see what your confusion is about. You will not get a data. I haven’t worked with CakePHP, but I assume $this->data is what you’d get from $_REQUEST['data']? You don’t get that on the server. data is a hash of what is getting submitted; you will directly get the $_REQUEST['name'] and $_REQUEST['id'] (which, I assume, translate into CakePHP as $this->name and $this->id).

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I want use html5's new tag to play a wav file (currently only supported

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.