Zend Framework autocomplete

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


That fix my problem:

-before:

source: 'ajax/getusers'

-now:

source: '/ajax/getusers'

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

链接地址: http://www.djcxy.com/p/28652.html

上一篇: AJAX操作完成它的工作,但总是出错

下一篇: Zend框架自动完成