【问题标题】:Zend Framework autocompleteZend 框架自动完成
【发布时间】:2014-04-29 23:09:18
【问题描述】:

我有自动完成的问题。我的 jQuery 版本是 1.11.0.min,jquery ui 是 1.9.1.min,jQuery 的 ajax 自动完成是 1.2.7。那是我的jQuery代码:

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

            });

这是我的 ajax/getusers 操作:

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');
}

}

当我打开 ajax/getusers 函数时 getClientsInfoByName 返回:

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

但是为什么会有错误信息:

错误:SyntaxError:JSON.parse:意外字符 源文件:http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js

【问题讨论】:

    标签: php jquery ajax zend-framework autocomplete


    【解决方案1】:

    这解决了我的问题:

    -之前:

    source: 'ajax/getusers'
    

    -现在:

    source: '/ajax/getusers'
    

    【讨论】:

      【解决方案2】:

      尝试将此example 与源作为调用jquery ajax 函数的un 函数进行调整

      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
                      }
                  }));
              }
          });
      },
      

      希望对你有所帮助。 请给我一个反馈

      【讨论】:

      • 我改变了我的答案。 :)
      • 如果您的解决方法与我的答案不同,您可以为有相同问题的人写一个答案吗?否则您能否验证我的答案以显示解决方案。
      猜你喜欢
      • 2012-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-09
      相关资源
      最近更新 更多