Jquery ui 在CakePHP2.0中使用JQuery UI自动完成
我在CakePHP2.0中实现jQueryUIAutoComplete时遇到问题。希望在杂货店列表视图中显示项目列表,以允许用户选择数据库中已有的项目,而不是创建新项目 应用程序Jquery: 视图中的项目窗体: 我不知所措,欢迎任何意见 在对Application.js进行了上述更改之后,我的网页上现在有了响应。根据数据库中当前包含的内容,它具有正确数量的结果,但是它是一个空响应。Firebug的回复如下:Jquery ui 在CakePHP2.0中使用JQuery UI自动完成,jquery-ui,cakephp,jquery-ui-autocomplete,cakephp-2.0,Jquery Ui,Cakephp,Jquery Ui Autocomplete,Cakephp 2.0,我在CakePHP2.0中实现jQueryUIAutoComplete时遇到问题。希望在杂货店列表视图中显示项目列表,以允许用户选择数据库中已有的项目,而不是创建新项目 应用程序Jquery: 视图中的项目窗体: 我不知所措,欢迎任何意见 在对Application.js进行了上述更改之后,我的网页上现在有了响应。根据数据库中当前包含的内容,它具有正确数量的结果,但是它是一个空响应。Firebug的回复如下: [{"value":null,"label":null},{"value":null,
[{"value":null,"label":null},{"value":null,"label":null},{"value":null,"label":null},{"value":null,"label":null}]
以下是我的回复标题:
Response Headers
Date Sun, 18 Sep 2011 14:48:37 GMT
Server Apache/2.2.11 (Win32) PHP/5.3.0
X-Powered-By PHP/5.3.0
Content-Length 113
Keep-Alive timeout=5, max=100
Connection Keep-Alive
Content-Type text/html; charset=UTF-8
Request Headers
Host localhost
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2
Accept application/json, text/javascript, */*; q=0.01
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection keep-alive
X-Requested-With XMLHttpRequest
Referer http://localhost/groceries/groclists/view/3
Cookie CAKEPHP=hu7ksthrlfms0lqod3rdq296f5
我不太清楚您在问什么,但以下是我在CakePHP 1.2和1.3中使用的Javascript:
$.ajax({
url: '/api/v1/zip_codes/utilities/' + zip + '/' + type + '.json',
type: 'GET',
dataType: 'json',
success: function( data, status ) {
var utility_type = data.Type.name;
var $provider_name = $('#Building' + utility_type + 'ProviderName');
var $provider_id = $('#Building' + utility_type + 'ProviderId');
// Massage the Cake data into something autocomplete-friendly
var $friendly = $.map( data.Utilities, function( util ) {
return { label: util.Utility.name, value: util.Utility.id };
});
// If more than one, populate the provider autocomplete options
$provider_name.autocomplete({
source: $friendly, // use the autocomplete-friendly data
minLength: 0,
focus: function( event, ui ) {
$provider_name.val( ui.item.label );
return false;
},
select: function( event, ui ) {
$provider_name.val( ui.item.label );
$provider_id.val( ui.item.value );
return false;
}
}).data( 'autocomplete' )._renderItem = function( ul, item ) {
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( '<a>' + item.label + '</a>' )
.appendTo( ul );
};
});
此代码段检索在给定邮政编码下运营的公用事业公司的名称和ID,只是为了提供一点上下文。有关更多信息,请参阅。我正在完成XHR加载:当我搜索蛋糕时。虽然问题解决了,但没有打印出任何内容,但不清楚原因。我怀疑Jquery不喜欢[][]
[{"value":null,"label":null},{"value":null,"label":null},{"value":null,"label":null},{"value":null,"label":null}]
Response Headers
Date Sun, 18 Sep 2011 14:48:37 GMT
Server Apache/2.2.11 (Win32) PHP/5.3.0
X-Powered-By PHP/5.3.0
Content-Length 113
Keep-Alive timeout=5, max=100
Connection Keep-Alive
Content-Type text/html; charset=UTF-8
Request Headers
Host localhost
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2
Accept application/json, text/javascript, */*; q=0.01
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection keep-alive
X-Requested-With XMLHttpRequest
Referer http://localhost/groceries/groclists/view/3
Cookie CAKEPHP=hu7ksthrlfms0lqod3rdq296f5
$.ajax({
url: '/api/v1/zip_codes/utilities/' + zip + '/' + type + '.json',
type: 'GET',
dataType: 'json',
success: function( data, status ) {
var utility_type = data.Type.name;
var $provider_name = $('#Building' + utility_type + 'ProviderName');
var $provider_id = $('#Building' + utility_type + 'ProviderId');
// Massage the Cake data into something autocomplete-friendly
var $friendly = $.map( data.Utilities, function( util ) {
return { label: util.Utility.name, value: util.Utility.id };
});
// If more than one, populate the provider autocomplete options
$provider_name.autocomplete({
source: $friendly, // use the autocomplete-friendly data
minLength: 0,
focus: function( event, ui ) {
$provider_name.val( ui.item.label );
return false;
},
select: function( event, ui ) {
$provider_name.val( ui.item.label );
$provider_id.val( ui.item.value );
return false;
}
}).data( 'autocomplete' )._renderItem = function( ul, item ) {
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( '<a>' + item.label + '</a>' )
.appendTo( ul );
};
});