Welcome Guest, Not a member yet? Register   Sign In
Database LiveSearch
#11

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

[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
#13

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

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

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

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

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

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

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

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

use this code.
#20

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





Theme © iAndrew 2016 - Forum software by © MyBB