Jump to content

Autocomplete feature not working


Afreen

Recommended Posts

Hi all,
    I am facing problem in autocomplete feature in my project. I am working in codeigniter mvc framework.

I have used autocomplete feature in my views folder. That is:

I have written the autocomplete code in my home page. when the home page is called via controller then the autocomplete in jquery does not work. But, the same thing works when the home page is called without controller.

For example:
when i call via controller its like:

public function index()
{
    $this->load->view(‘home’);
}
it does not work.

And then when I click on home page link:
Home it works.

What is the problem with the autocomplete feature while calling from controller.

Please suggests.

Link to comment
https://forums.phpfreaks.com/topic/279351-autocomplete-feature-not-working/
Share on other sites

<script type="text/javascript">
		jQuery(function(){
		//jQuery(document).ready(function(){

			jQuery("#name").autocomplete({
							
				source: "overall/search", // path to the overall/search method
				minLength: 1
			});
			 
		});
	</script>
	
<form action="<? echo site_url();?>/overall/search_all" name="overall_search" id="overall_search" onsubmit="return search_Val();" method="post">
                                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                    <tr>
                                        <td>
                                            <input name="name" id="name" type="text" class="searchBox1" border="1" value="" 
											placeholder = "Enter event name or location"/>
                                        </td>
                                        <td width="80">
                                            <input type="submit"  value="Search" border="0" class="butt" style="margin-top:0px;" />
                                        </td>
</tr>
</table>
</form>

The controller is called when the input type name is entered, 

class Overall extends CI_Controller 
{
	
	// $ Afreen A Kazi -28/05/2013 - The search() is called when the single search field is searched in the home page. It navigates
	// to the display_venue page in views folder. - START
	public function search()
	{
					
			$this->load->model('find_overall');
			if (isset($_GET['term'])){
				$q = strtolower($_GET['term']);
				$this->find_overall->search($q);
			}
	}
	// $ Afreen A Kazi - 28/05/2013 - search() - END
}

After this a model named as find_overall is called

class Find_overall extends CI_Model
{

	// $ Afreen A Kazi - 07/06/2013 - The search() gets all the list of event_type or event_location and displays on display
	// venuez page. - START
	public function search($q)
	{
		$query = $this->db->query("select distinct event_name from event_details where event_name like '$q%'");
		$query1 = $this->db->query("select distinct event_location from event_details where event_location like '$q%'");
		if($query->num_rows > 0){
			foreach ($query->result_array() as $row){
				$row_set[] = htmlentities(stripslashes($row['event_name'])); //build an array
			}
			echo json_encode($row_set); //format the array into json data
		}
		if($query1->num_rows > 0){
			foreach ($query1->result_array() as $row1)
			{
				$row1_set[] = htmlentities(stripslashes($row1['event_location']));
			}
			echo json_encode($row1_set);
		}
	}
	// $ Afreen A Kazi - 07/06/2013 - search() - END
}

This code works perfectly fine when the home page is called via a href link i.e. <a href="<? echo site_url();?>/home">Home</a>

But, when the same thing is called via controller i.e. $this->load->view('home'); it doesn't. Please help.

  • 4 weeks later...

Hey the problem is solved. I just had to change one line in the javascript.

 

Instead of 

<script type="text/javascript">
		jQuery(function(){
		//jQuery(document).ready(function(){

			jQuery("#name").autocomplete({
							
				source: "overall/search", // path to the overall/search method
				minLength: 1
			});
			 
		});
	</script>

i need to change in the source line :

 

source: "<? echo site_url('overall/search');?>",

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.