使用jQuery从视图传递多个变量到codeigniter控制器 [英] passing multiple variables to codeigniter controller from view with jquery
问题描述
我有一个看法,使用jquery向控制器发布一些信息。控制器然后使用发布信息运行一些逻辑并将结果返回到我的视图中的div。
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.
我的视图语法是:
$.post("get_link_load_options", { varlatitude: latitude, varlongitude: longitude }).done(function(data) {
$('#results').html(result);
});
我的控制器语法是:
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);
}
}
目前,使用此语法div
Currently, with this syntax the div is populated with the value of the variable latitude and is duplicated.
如何显示视图 link_order_options
的内容,如何访问控制器中的每个变量,以便我可以使用它执行逻辑。当前$ q获取数据变量/数组。
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.
如何将每个纬度和经度作为PHP变量存储在我的控制器中?
how do I store each of latitude and longitude as a PHP variable in my 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);
}
}
模型
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>
这篇关于使用jQuery从视图传递多个变量到codeigniter控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!