0
我想通過使用jQuery UI界面庫(jquery自動完成)從我的查看頁面獲取部門的名稱根據用戶輸入ajax調用。自動完成功能看起來像在CakePhp-網絡錯誤:404沒有找到Ajax自動完成
$("#auto_complete").autocomplete({
source: function(request, response) {
$.ajax({
url: "/employees/getAddress",
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,
value: item.id
}
}));
}
});
},
minLength: 2,
select: function(event, ui) {
log(ui.item ?
"Selected: " + ui.item.label :
"Nothing selected, input was " + this.value);
},
open: function() {
$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
},
close: function() {
$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
}
});
在這裏,我想提出的行動()的調用叫的getAddress
它看起來像
class EmployeesController extends AppController {
//var $components = array('Autocomplete');
public $components = array('RequestHandler');
var $helpers = array('Javascript', 'Ajax');
/**
* index method
*
* @return void
*/
//var $helpers = array('Ajax');
public function getAddress() {
$this->log($this->params, 'debug');
$this->layout = 'ajax';
$departments = $this->Department->find('all', array(
'conditions'=>array('Department.name LIKE'=>$this->params['url']['q'].'%'),
'fields'=>array('name', 'id')));
$this->log($departments, 'debug');
//$this->set('departments', $departments);
$this->set(compact('departments'));
}
但每當我想提出AJAX調用我得到錯誤
「NetworkError:404 Not Found - http://localhost/employees/getAddress?callback=jQuery1710012251482368207167_1333972423088&featureClass=P&style=full&maxRows=12&name_startsWith=sal&_=1333972426249」
如何解決這個問題?
C:\ Xampplite文件\ htdocs中\ CakePHP的\應用程序這是我的應用程序的路徑 – maaz 2012-04-09 12:15:56
你能告訴我如何給正確的網址嗎? 做網址:「app/employees/getAddress」,有道理嗎? – maaz 2012-04-09 12:19:12
我正在嘗試自動完成相同的方式,但我不知道如何在從ajax調用接收數據時調用響應函數。您能否延長顯示如何調用回覆回調的答案? – sparrow 2013-07-07 13:45:03