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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:03:04+00:00 2026-06-16T09:03:04+00:00

I am making a small search functionality where i have placed .ctp files into

  • 0

I am making a small search functionality where i have placed .ctp files into elements so that i can achieve ajax post without reloading the entire page and only render the element.

The element is very simple, it creates a li item with request data passed from the controller.

<li class="span2">
<a  class="pull-left" href="">
    <img  class="media-object" src="<?php $img_path = $result['Person']['profile_image']; echo $img_path;?>">
</a>
<div class="media-body">
    <label class="person-media">
        <?php
        $firstName = ucfirst($result['Person']['first_name']);
        $lastName = ucfirst($result['Person']['last_name']);

        echo $firstName;
        echo "<br>";
        echo $lastName;
        ?>
    </label>
</div>

In my search action, i want to keep the entire skeleton (header, footer, search div holder) and just render the list items in the unordered list. But on search click, the entire page loads

Here i am attempting to set the data

//transform POST into GET
    if($this->request->is("post")) {
        $url = array('action'=>'manage');
        $filters = array();

        if(isset($this->data['searchFor']) && $this->data['Search.name']){
            //maybe clean up user input here??? or urlencode??
            $filters['Search.name'] = $this->data['Search.name'];
        }
        //redirect user to the index page including the selected filters
        $this->redirect(array_merge($url,$filters));
    }

    $conditions = array();
    //
    // filter by name
    //
    if(isset($this->passedArgs['Search.name'])) {
        $conditions["Person.first_name LIKE"] = "%".$this->passedArgs["Search.name"]."%";

    }
    //paginate as normal
    $this->paginate = array(
        'conditions' => $conditions,
        'order' => array('Person.first_name ASC'),
        'limit' => 12
    );
    $this->layout = "main";
    $this->set("results",$this->paginate("Person"));
    **$this->render('manage');** // rendering on the element loads everything

After finding my results from the query, manage.ctp loads everything.

  </div>
<ul id="students-list" class="students-ist">
   <?php

    if(!empty($results)){

        foreach($results as $result){
            echo $this->element('singleuser', array('result' => $result));
        }
    }

    ?>

</ul>

How can i using Ajax and form submission load just an element inside a div without reloading the entire page on every search.

  • 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-16T09:03:05+00:00Added an answer on June 16, 2026 at 9:03 am

    There are several ways to get part of a full page from server and place only parts of it into page in browser.

    Following is submit handler for search form that will make AJAX call. WIthin the AJAX complete callback will replace student list items with new ones

    /* place code in script tag or external file after jQuery.js loads*/
    $(function(){
        /* adjust selector to match ID of form*/
        $('#searchForm').submit(function(){
              /* sends form data retrieved in php as if form submitted through browser defalt method*/
               /* "this" is the form, serialize will formencode all fields in form*/
              var dataToServer=$(this).serialize();
              $.get( 'pageUrl.php', dataToServer, function(response){
                    /* AJAX has returned page, "response" is the full html of page*/
                   /* get the items from list from response*/
                    var studentListItems= $(response).find('#students-list').html();
    
                    /* replace the list items in active page*/
                    $('#students-list').html(studentListItems);
    
               });
           /* prevent form default submit*/
           return false;
        });
    
    })
    

    Once you get Cake controller returning just the LI’s you want, you can dump response straight into the list:

    $('#students-list').html(response);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a small section of an app (phone and website) that can
I'm making a small tool application that user can minimize in the taskbar .
Hello i am making an small application in which i want search functionality i
I am making a small application where I have to call search dialog on
I'm making an flight search app with Sencha Touch and have encountered a small
I'm making a small webpage that is going to execute links, en specifics magnet
I'm making a small system for personal use on that I want to handle
I am current making some small JS game in Netbeans and I have started
I am making a small calculator (just for JavaScript learning) and I have two
I'm making a small userControl library that searches for active server on a specific

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.