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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:34:33+00:00 2026-06-14T06:34:33+00:00

When using jQuery AJAX in cakePHP 1.3, the AJAX response includes the full layout

  • 0

When using jQuery AJAX in cakePHP 1.3, the AJAX response includes the full layout rather than just the array with dataset from the model. How to I prevent this whole page from being rendered? I have tried to use $this->autoRender = false; and $this->layout = ‘ajax’, but this did not solve the problem. It actaully produced no response in the returned data.

My controller action is:

    public function search() {
    if (empty($this->data)) {
    } else {
        // $this->autoRender = false;
        // $this->layout = 'ajax';
        $request = $this->data;
        $this->set('data', $this->Event->search($request['Event']['search']), 'host');
    }  
}

And my view is:

      <!-- app/views/events/search.ctp -->

<h1>Corporate Events</h1> 

<form method="post" action="search">
    <input type="text" name="search" id="search_box" class='search_box'/>
    <input type="submit" value="Search" class="search_button" /><br />
</form>

<p><?php echo $html->link("Add Event", "/events/add"); ?> 

<table> 
    <tr> 
        <th style='width:100px'>Id</th> 
        <th style='width:100px'>Title</th> 
        <th style='width:100px'>Host</th> 
        <th style='width:100px'>Description</th> 
        <th style='width:100px'>Action</th> 
    </tr> 

<div id= "results"></div>

<?php foreach ($data as $event): ?> 
    <tr> 
        <td><?php echo $event['id']; ?></td> 
        <td> 
            <?php echo $html->link($event['event_title'],'/events/view/'.$event['id']);?> 
        </td> 
        <td><?php echo $event['host']; ?></td> 
        <td><?php echo $event['description']; ?></td> 
        <td> 
            <?php echo $html->link( 
                'Delete',  
                "/events/delete/{$event['id']}",  
                null,  
                'Are you sure?' 
            )?> 
            <?php echo $html->link('Edit', '/events/edit/'.$event['id']);?> 
        </td> 
    </tr> 
<?php endforeach; ?> 

</table> 

<script type="text/javascript">

$(function() {

    $(".search_button").click(function() {
        var searchString    = $("#search_box").val();
        var data = {'data[Event][search]':searchString};

        if(searchString) {

            $.ajax({
                type: "POST",
                url: "/events/search",
                data: data,
                beforeSend: function(html) { // this happens before actual call
                    $("#results").html('');
                    $("#searchresults").show();
                    $(".word").html(searchString);
                },
                success: function(html){ // this happens after we get results
                    $("#results").show();
                    $("#results").append(html);
                }
            });    
        }
        return false;
    });
});
</script>

Thanks!

  • 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-14T06:34:35+00:00Added an answer on June 14, 2026 at 6:34 am

    I don’t understand your question well, but this will help you with displaying to your view without the layout being echoed wholly.

    Put this on the javascript inside the view,

    <script type="text/javascript">
    
    $(function() {
    
        $(".search_button").click(function() {
            var searchString    = $("#search_box").val();
    
            if(searchString) {
    
                $.ajax({
                    url: "/events/search/" + searchString,
                    beforeSend: function() { // this happens before actual call
                        $("#results").html('');
                        $("#searchresults").show();
                        $(".word").html(searchString);
                    },
                    success: function(data){ // this happens after we get results
                        $("#results").show();
                        $("#results").append(data);
                    }
                });    
            }
            return false;
        });
    });
    </script>
    

    Then use the code below for your controller,

    public function search($data=null) {
        $this->autoRender = false;
        //your code here;
        return $data;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jQuery ajax method to get response from my server. Here's my
I am using jQuery ajax to pass a string array to a page method.
I am using CakePHP 1.26 . I was trying to use jQuery Ajax to
I'm just starting using cakePHP and I saw on that there was an AJAX
I am using ajax with jQuery in my cakePHP application. and my javascript function
I am using CakePHP 1.26 and CDN JQuery in this URL: http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js In a
Using Jquery AJAX to get a value from a PHP script. This line works
Using jQuery Ajax to fetch data from local server: it works well with IE8
I am looking to implement a 5 star rating using jQuery Ajax in CakePHP.
I'm using the jQuery ajaxForms plugin to make an ajax submit to my CakePHP

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.