0

I have a view, that using jquery posts some information to the controller. the controller then runs some logic using the post information and returns the result to a div in my view.

my view syntax is:

 $.post("get_link_load_options", { varlatitude: latitude, varlongitude: longitude }).done(function(data) { 
      $('#results').html(result);    
  });

My Controller syntax is:

function get_link_load_options(){
    $this->load->model('Sales_model');
    if (isset($_POST['data'])){
        $q = strtolower($_POST['data']);
        $data['result'] = $this->Sales_model->get_link_load_options($q);
        $this->load->view('sales\link_order_options',$data);
    }
}

Currently, with this syntax the div is populated with the value of the variable latitude and is duplicated.

How can I show the contents of the view link_order_options and also, how do I access each variable in the controller so I can perform logic with it. currently $q fetched the data variable/array.

how do I store each of latitude and longitude as a PHP variable in my controller?

Thanks as always.

2
  • 1
    You can use Codeigniter's Input Class to retrieve the post data. Check answer below. Commented May 23, 2013 at 11:45
  • 1
    You're not posting any data to the controller, only varlatitude and varlongtitude. Which means in the controller you'll find them by accessing $_POST['varlatitude'] and $_POST['varlongtitude']. Commented May 23, 2013 at 12:18

2 Answers 2

2

Here is a demonstration

Controller

function get_link_load_options()
{
    if($this->input->is_ajax_request()){
        $varlatitude    =   $this->inpput->post('varlatitude');
        $varlongitude   =   $this->inpput->post('varlongitude');

        $data['result'] =   $this->Sales_model->get_link_load_options($varlatitude , $varlongitude);
        $this->load->view('sales\link_order_options',$data);
    }
}

Model

public function get_link_load_options($latitude , $longitude)
{
    //blah blah
}

Ajax

var latitude    =   $('#latitude_input_field_id').val();
var longitude   =   $('#longitude_input_field_id').val();

$.post("get_link_load_options", { varlatitude: latitude, varlongitude: longitude }).done(function(data) { 
  $('#results').html(data);    
}); 

html

<input type="text" id="latitude_input_field_id" />  
<input type="text" id="longitude_input_field_id" /> 

<div id="results">

</div>
Sign up to request clarification or add additional context in comments.

Comments

1

You can use Codeigniter's Input Class to retrieve the post data.

This might help you:

if($this->input->post()) {
    $varlatitude = $this->input->post('varlatitude'); 
    $varlongitude = $this->input->post('varlongitude');
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.