Welcome Guest, Not a member yet? Register   Sign In
No value from input->post
#1

[eluser]Shiju S S[/eluser]
I have the script as
Code:
$(function()
    {   $( "#tags" ).autocomplete({
  source: function(req, add){
            
            var fields = $("#tags").val(); //Get input
                $.ajax({
                    url: '<?php echo base_url('frontpage/autocomplete');?>',
                    dataType: 'json',
                    type: 'POST',
                    data: fields,
                    success: function(data){
                        add(data);
                    }
                });},
minLength: 0,
  select: function( event, ui )
                {
   log( ui.item ?
      "Selected: " + ui.item.value + " aka " + ui.item.id :
      "Nothing selected, input was " + this.value );
  }
  });
    });

The input is:
Code:
<div class="ui-widget">
            <label for="tags">Tags: </label>
            &lt;input id="tags" name="name"&gt;
        </div>

I have the controller frontpage with autocomplete mehod
Code:
public function autocomplete()
    {  

  $searchterm  = $this->input->post('fields');
     $query ="SELECT DISTINCT category FROM listeditems WHERE MATCH (category,subcategory,title,details,address) AGAINST ('$searchterm') > 0";
  $result = $this->sales_exe_details_db->get_results($query);
        
  if($result)
  { $i=0;
   foreach($result as $row):
  
   $data[] = array('id' => $i, 'label' => 'group', 'value'=> $row->category);
    $i++;  
   endforeach;    
  }
  echo json_encode($data);
    }

I am not getting any value in the $searchitem. Please help
#2

[eluser]capypara[/eluser]
Just to make sure its not an error, is $searchterm supposed to be $searchitem (or the other way round)?
#3

[eluser]aquary[/eluser]
Isn't the $.ajax data in a json format, with keys and values, or a query string?

Code:
$.ajax({
                    url: '&lt;?php echo base_url('frontpage/autocomplete');?&gt;',
                    dataType: 'json',
                    type: 'POST',
                    data: {fields:$("#tags").val()},
                    success: function(data){
                        add(data);
                    }
                });},
#4

[eluser]InsiteFX[/eluser]
Code:
&lt;head&gt;
// Replace $ in script with s
<$cript type="text/javascript" charset="utf-8">
    //&lt;![CDATA[
        var base_url = "&lt;?php echo base_url();?&gt;";
    // ]]>
</$cript>
&lt;/head&gt;

url: base_url + "frontpage/autocomplete",
#5

[eluser]Shiju S S[/eluser]
I got it corrected on your help: Thanks. Two corrections were needed.
1. The base url was wrongly used
2. var field was not getting value.



Code:
[b]<$cript type="text/javascript" charset="utf-8">[/b]
var base_url = "&lt;?php echo base_url();?&gt;";
$(function()
    {   $( "#tags" ).autocomplete({
  source: function(req, add){
                
       $.ajax({
                    url: base_url + "frontpage/autocomplete",
                    dataType: 'json',
                    type: 'POST',
                   data: {fields:$("#tags").val()},
                    success: function(data){
                        add(data);
                    }
                });},
minLength: 0,
  select: function( event, ui )
                {
   log( ui.item ?
      "Selected: " + ui.item.value + " aka " + ui.item.id :
      "Nothing selected, input was " + this.value );
  }
  });
    });  
</$cript>

Thanks Once again




Theme © iAndrew 2016 - Forum software by © MyBB