2017-08-07 34 views
1

這是工作自動完成我認爲的代碼,但它顯示了我500內部服務器錯誤蛋糕PHP 500內部服務器錯誤

image is in link

我,如果我不使用我不知道是怎麼回事錯正確的網址或其他問題。

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 }); 
    } 
    }); 
+0

你的錯誤日誌告訴你什麼? – drmonkeyninja

+0

ajax調用中的dataType是什麼? –

+0

@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)) –

回答

0

根據您的意見錯誤消息,該loadComponent方法沒有定義。

我會建議加載RequestHandler組件附近控制器的頂部,例如:

class ClinicController extends AppController { 
    public $components = array('Request'); 

也有另一種語法裝載組件上飛:

$this->Request = $this->Components->load('Request'); 

參考:https://book.cakephp.org/2.0/en/controllers/components.html

+0

我解決了錯誤alreay ..但問題是代碼沒有工作..你可以告訴我爲什麼 –