2012-06-04 61 views
-1

試圖讓一些jQuery代碼發佈一個值到php文件我有,並返回一個數組數組。jquery發佈到php文件

其基本思想是搜索數據庫,然後用值填充引導程序的鍵入。在CodeIgniter中工作。

搜索控制器:目前填補了預輸入

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class Search extends CI_Controller { 


public function index() 
{ 

} 

public function getSearchResults() 
{ 

    $partialSearch = $_POST['partialSearch']; 
    if (strlen($partialSearch) > 5) { 
    $this->db->select('mobile_number'); 
    $this->db->like('mobile_number', $partialSearch); 
    $query = $this->db->get('phone_lines'); 

    $result = $query->result(); 
    $data = ""; 
    foreach($result as $row){ 
    $data = $data . "<div>" . $row->mobile_number . "</div>"; 
    } 
    echo $data; 
    } 

} 
} 

的jQuery:

<script> 
     //searches the database for mobile numbers 
     $(function() { 
     var searchItem = $("#typeahead").val(); 
     var itemsArray = [ 
       "1111111111", 
       "2222222222", 
       "3333333333" 
       ]; 
     //push to search controller, receive back array of mobile numbers that match 

      $("#typeahead").typeahead({ 

       source: itemsArray 
      }); 
     }); 
    </script> 

所以,我不知道如何將搜索框的值張貼到PHP,那麼如何在返回時將其正確格式化。有什麼想法嗎?對所有這些都很新穎。甚至不確定這是可能的。任何幫助深表感謝。

+1

您是否首先嚐試了[docs網站](http://api.jquery.com/category/ajax/)的運氣? – gdoron

+0

我認爲我們需要在meta上提出一個問題,使搜索框增大300%。 – gorelative

回答

0

$.ajax,$.post$.getjson是那裏的許多jQuery函數中的一部分。