CodeIgniter Forums
Database LiveSearch - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Database LiveSearch (/showthread.php?tid=52125)

Pages: 1 2 3 4


Database LiveSearch - El Forum - 05-30-2012

[eluser]boltsabre[/eluser]
I haven't played with ajax and CI for a while, but I think if you just put your code from your getSearchResults.php file into your contoller (inside a function/method) and change your

Code:
$.post("getSearchResults.php",{partialSearch:value}, function(data){

to point to your controller/function instead of a file. That should work then!


Database LiveSearch - El Forum - 05-30-2012

[eluser]joe.afusco[/eluser]
When I point it to the controller/function, it throws the following error:

POST http://localhost/crm/index.php/search/getSearchResults

500 Internal Server Error


Database LiveSearch - El Forum - 05-30-2012

[eluser]sanir[/eluser]
put code of your search controller.


Database LiveSearch - El Forum - 05-30-2012

[eluser]joe.afusco[/eluser]
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Search extends CI_Controller {


public function index()
{
  
}

public function getSearchResults()
{
  $partialSearch = $_POST['partialSearch'];
  $query = $this->db->select('email_address')
  ->like('email_address', $partialSearch);
  ->get('users');
  
  $result = $query->result();
  $data = "";
  foreach($result as $row){
     $data = $data . "<div>" . $row->email_address . "</div>";
  }
  echo $data;
}
}



Database LiveSearch - El Forum - 05-30-2012

[eluser]sanir[/eluser]
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Search extends CI_Controller {


public function index()
{
  
}

public function getSearchResults()
{
  $this->load->database();  
  $partialSearch = $_POST['partialSearch'];
  $query = $this->db->select('email_address')
  ->like('email_address', $partialSearch);
  ->get('users');
  
  $result = $query->result();
  $data = "";
  foreach($result as $row){
     $data = $data . "<div>" . $row->email_address . "</div>";
  }
  echo $data;
}
}

Try this code.


Database LiveSearch - El Forum - 05-30-2012

[eluser]joe.afusco[/eluser]
Produces the same error.


Database LiveSearch - El Forum - 05-30-2012

[eluser]sanir[/eluser]
In you view file
Quote:$("#search_results".html(data));

Change it to
Code:
$("#search_results").html(data));



Database LiveSearch - El Forum - 05-30-2012

[eluser]joe.afusco[/eluser]
New errors now from Firebug:

missing ; before statement
[Break On This Error]

$("#search_results").html(data));

user_home (line 9, col 35)

getSearchResults is not defined
[Break On This Error]

getSearchResults(this.value);

Code is now:

Code:
function getSearchResults(value) {
   $.post("/crm/index.php/search/getSearchResults",{partialSearch:value}, function(data){
    $("#search_results").html(data));
   });
  }



Database LiveSearch - El Forum - 05-30-2012

[eluser]sanir[/eluser]
Code:
$("#search_results").html(data);

use this code.


Database LiveSearch - El Forum - 05-30-2012

[eluser]joe.afusco[/eluser]
With that adjustment, it gives the internal server error again.