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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:34:23+00:00 2026-05-22T01:34:23+00:00

I’ve used AJAX a lot in PHP, but now I’m trying to learn CakePHP,

  • 0

I’ve used AJAX a lot in PHP, but now I’m trying to learn CakePHP, and haven’t been able to ANY good/simple examples of how to use AJAX with CakePHP 1.3. The only examples I’ve been able to find are for paging (not what I need), or use the deprecated helpers while forcing you to include scriptaculous or prototype.

Are there ANY good/simple examples of how to use AJAX w/ CakePHP 1.3? Or is it something someone could explain here?

All I want to do is have the user click a link, which retrieves the contents of a php file, and inserts it into a div. The contents of the php file would be altered based on some POST or GET variables sent w/ the ajax call. Seems simple enough 🙁

  • 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-22T01:34:24+00:00Added an answer on May 22, 2026 at 1:34 am

    This is the pattern that I use in CakePHP 1.3.x. The process is generally:

    1. Creating alternative json-oriented layout and view files
    2. Detecting if the incoming request is AJAX
    3. Explicitly rendering the alternative json layout/view instead of text/html

    Be sure to include RequestHandler component and JsHelper in your app controller.

    In a given controller:

    function test() {
        if($this->RequestHandler->isAjax()) {
            $this->set('data', $this->data);
            // Explicit call to render an ajax response, using a layout and view made specifically for ajax
            $this->layout = 'json';
            $this->render('ajax_test');    
        }
        // else render views/controllername/test.ctp like normal
    }
    

    Your app/views/layouts/json.ctp file:

    <?php
        header("Pragma: no-cache");
        header("Cache-Control: no-store, no-cache, max-age=0, must-revalidate");
        header('Content-Type: text/x-json');
        header("X-JSON: ".$content_for_layout);
    
        echo $content_for_layout;
    ?>
    

    Your app/views/controllername/ajax_test.ctp file should contain only:

    <?php echo $js->object($data); ?>
    

    Now, on your page that’s actually going to make an ajax call, it might look something like this, with jQuery code:

    <div id='status'></div>
    <?php echo $form->create('Test', array('id'=>'testForm')),
               $form->input('message'),
               $form->end();
    ?>
    <script type='text/javascript'>
        $('#testForm').submit(function(event) {
        event.preventDefault(); // interrupt form submission
        $.ajax({
            type: "POST",
            url: "/controllername/test",
            data: $('#testForm').serialize(),
            success: function(data, textStatus, xmlHttpRequest) {               
                $("#status").html(data.Test.message);
            },
            error: function(jqXHR, textStatus, errorThrown) {
                alert("There was a problem processing the request: " + jqXHR);
            }
        });
    });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I used javascript for loading a picture on my website depending on which small
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have text I am displaying in SIlverlight that is coming from a CMS
I have a JSP page retrieving data and when single or double quotes are
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.