2015-05-04 92 views
2

在搜索觀,我有這種形式:Codeigniter在同一視圖中顯示搜索結果?

<form class="form-horizontal col-centered" method="POST"action="Search/search"> 
    <div class="form-group"> 
     <div class="col-xs-4 col-centered "> 
      <input type="text" class="form-control" id="inputPassword3" placeholder="Type something" name="title"> 
     </div> 
    </div> 
     <div class="form-group"> 
      <div class="col-sm-offset-2 col-sm-10 col-centered"> 
       <input class="btn btn-default" type="submit" value="Search"name="submit2"> 
      </div> 
     </div> 
</form> 

表單動作設置爲:行動= 「搜索/查找」,在CONTROLER

搜索-DC型和SEACH功能。所有做工精細,之後提交表單,我得到的結果,但結果表明在:

http://localhost/ci/index.php/Search/search 

我的想法是,以顯示在哪裏形式相同的觀點功能搜索的結果,所以提交表格後,才能得到結果,對搜索視圖。

Tnx

+0

它更好地使用ajax進行搜索,因爲它將響應傳遞給相同的html頁面,並且可以使用返回的響應更新您的html –

+0

我會嘗試一下,tnx – pavlenko

+0

我會使用jqery ajax而不是純ajax。把事情簡單化。 –

回答

0
在表單( action="Search/search")設置控制器 Search和調用函數 search

。在這種情況下,當你的函數執行時,它會返回你的search函數的數據。

所以你的URL看起來像http://localhost/ci/index.php/Search/search

如果你想從URL中移除2檢索詞,你可以傳遞數據的Searchindex控制器。所以這將解決。那麼它看起來像http://localhost/ci/index.php/Search