1
這是工作自動完成我認爲的代碼,但它顯示了我500內部服務器錯誤蛋糕PHP 500內部服務器錯誤
我,如果我不使用我不知道是怎麼回事錯正確的網址或其他問題。
public function search(){
$this->loadComponent('RequestHandler');
if ($this->request->is('ajax'))
{
$name = $this->request->query['term'];
$resultArr = $this->Invoices
->find()
->where(
['Invoices.name LIKE' => ($name . '%')],
['Invoices.name' => 'string']);
$resultsArr = [];
foreach ($resultArr as $result)
{
$resultsArr[] = ($result['name']);
}
$this->set('resultsArr', $resultsArr);
// This line is what handles converting your array into json
// To get this to work you must load the request handler
$this->set('_serialize', ['resultsArr']);
}
}
這是我的看法代碼:
<?php echo $this->Form->input('name', ['type' => 'text']); ?>
$.ajax({
type: "POST",
url: "<?php echo Router::url(array('controller' => 'Clinics','action' => 'search')); ?>",
success: function(response) {
$("#name").autocomplete({ source: response });
}
});
你的錯誤日誌告訴你什麼? – drmonkeyninja
ajax調用中的dataType是什麼? –
@drmonkeyninja 48錯誤:[錯誤]調用未定義方法ClinicsController :: loadComponent() 請求URL:/ mydentisttree /診所/搜索 堆棧跟蹤: #0 [內部功能]:ClinicsController->搜索() #1 /var/www/html/mydentisttree/lib/Cake/Controller/Controller.php(491):ReflectionMethod-> invokeArgs(Object(ClinicsController),Array) #2/var/www/html/mydentisttree/lib/Cake/Routing/Dispatcher.php(193):Controller-> invokeAction(Object(CakeRequest)) #3 /var/www/html/mydentisttree/lib/Cake/Routing/Dispatcher.php(167):Dispatcher - > _ invoke(Object (ClinicsController),Object(CakeRequest)) –