Concatenate several fields to be displayed in autocomplete using AJAX in cakephp

综合技术 2018-05-27 阅读原文

currently my autocomplete works in displaying the first name of the user, but I want to concatenate the first name, last name and etc. How do I achieve this in the following code?

    $(function() {
            source: function( request, response ) {
                    url: 'Html->url(array('controller' => 'searches', 'action' => 'suggestUser')); ?>',
                    dataType: "json",
                    data: {
                        //request.term is the value of the current textbox.
                        term: request.term
                    success: function( data ) {
                        response( $.map( data, function( item ) {
                            return {
                                label: item.User.firstName,
                                value: item.User.firstName

            minLength : 1

In my controller, the following codes below is my logic to search for that field.

function suggestUser() {

        if (isset($_GET["term"])) {
            $term = $_GET["term"];

            $result = $this->User->find('all', array(
                'conditions' => array(
                    'User.firstName LIKE' => $term . '%'
                'fields' => array(
            if ($term) {
                $this->set('results', $result);
                $this->view = 'Json';
                $this->set('json', 'results');
Hello, buddy!

责编内容by:Hello, buddy!阅读原文】。感谢您的支持!


AJAX Recommendations for Beginners Ajax basics for beginners $.ajax({ type: "GET", data: "id=...
KLIPSE secured mode Introduction Code interactivity comes at a price: it gives unlimited power to ...
HTML form using Ajax and PHP not working Just wondering if anyone can give me a hand? I am trying to learn bits of Ajax...
AJAX跨域“Access-Control-Allow-Origin” JAVA WEB个人解决方法... ajax跨域访问是一个老问题了,解决方法很多,比较常用的是JSONP方法,JSONP方法是一种非官方方法,存在各种问题,大家可以自行百度。 我们项目使用Sp...
AJAX multi-domain calls during development&col... I am developing applications using Angular and the client side is 100% JS. I am ...