CodeIgniter Forums

Full Version: Database LiveSearch
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4

El Forum

[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!

El Forum

[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

El Forum

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

El Forum

[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;
}
}

El Forum

[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.

El Forum

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

El Forum

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

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

El Forum

[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));
   });
  }

El Forum

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

use this code.

El Forum

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

Pages: 1 2 3 4