2
votes

I have problem with autocomplete. My jQuery version is 1.11.0.min, jquery ui is 1.9.1.min and ajax autocomplete for jQuery is 1.2.7. That is my jquery code:

$(function () {
                $('.client').autocomplete({
                    source: 'ajax/getusers',
                    minLength: 2,
                    onSelect: function (suggestion) {
                    }
                });

            });

That is my ajax/getusers action:

class AjaxController extends Zend_Controller_Action
{

public function init() {
    $this->_helper->layout()->disableLayout();
    $this->_helper->viewRenderer->setNoRender(true);
}

public function getusersAction()
{
    $dbClients = new Application_Model_DbTable_Clients();


    $dbClients->getClientsInfoByName('v');
}

}

When I open ajax/getusers function getClientsInfoByName return:

[{"id":"1","value":"vel vele","label":"vel vele"}]

But why have error message:

Error: SyntaxError: JSON.parse: unexpected character Source File: http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js

2

2 Answers

1
votes

That fix my problem:

-before:

source: 'ajax/getusers'

-now:

source: '/ajax/getusers'
0
votes

Try to adapt this example with source as un function which call jquery ajax function

function( request, response ) {
    $.ajax({
        url: "ajax/getusers",
        dataType: "jsonp",
        data: {
            featureClass: "P",
            style: "full",
            maxRows: 12,
            name_startsWith: request.term
        },
        success: function( data ) {
            response( $.map( data.geonames, function( item ) {
                return {
                    label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
                    value: item.name
                }
            }));
        }
    });
},

I hope it will help you. Please let me a feedback