I want to send a post from HTML that contains info about a certain form to a controller in code igniter. The I want the controller to process the info and loads a certain page inside a div. Here is my code. I think I'm supposed to use something like .html or something? I'm not quite sure, I dont understand it
我想从HTML发送一个帖子,其中包含有关某个表单的信息到代码点火器中的控制器。我希望控制器处理信息并在div中加载某个页面。这是我的代码。我想我应该使用像.html之类的东西?我不太确定,我不明白
The controller
控制器
function search_friend(){
//this function gets text from text field and searches for a user and returns all users similar to this dude
// $this->input->post($searchFriendForm);
// $this->input->post($searchFriendText);
$this->load->model('userProfile_m');
$people = $this->userProfile_m->get_user_by_name($this->input->post($searchFriendText));
$this->load->view('addFriendSearchResult',$people);
}
the form in html
html中的表单
<form method="post" action="" name="searchFriendForm" id="add-friend-search">
<input type="text"/ name="searchFriendText">
<input type="button" class="small green button" id="add-friend-button" />
</form>
the jquery function
jquery函数
$("#add-friend-button").click(function(){ //start click
$.post("<?php echo site_url('userProfile/search_friend'); ?>", $("#add-friend-search").serialize());
$("#insert-activity").load("<?php echo base_url().''?>system/application/views/addFriendSearchResult.php");
$("#add-friend-search").slideUp("slow",function(){});
}); //end click
1 个解决方案
#1
1
Firstly, in your controller change this line like this (u need to pass the string name of the field here):
首先,在您的控制器中更改此行(您需要在此处传递字段的字符串名称):
$people = $this->userProfile_m->get_user_by_name($this->input->post('searchFriendText'));
Next, change your jQuery to be like this:
接下来,将您的jQuery更改为:
$("#add-friend-button").click(function(){ //start click
$.post("<?php echo site_url('userProfile/search_friend'); ?>",
$("#add-friend-search").serialize(),
function(data){
$("#insert-activity").html(data);
});
$("#add-friend-search").slideUp("slow",function(){});
}); //end click
You cant call your view directly, and you don't need to. The post should return the data, which you can write out to your #insert-activity
element.
你不能直接打电话给你的观点,你不需要。帖子应该返回数据,您可以将其写入#insert-activity元素。
#1
1
Firstly, in your controller change this line like this (u need to pass the string name of the field here):
首先,在您的控制器中更改此行(您需要在此处传递字段的字符串名称):
$people = $this->userProfile_m->get_user_by_name($this->input->post('searchFriendText'));
Next, change your jQuery to be like this:
接下来,将您的jQuery更改为:
$("#add-friend-button").click(function(){ //start click
$.post("<?php echo site_url('userProfile/search_friend'); ?>",
$("#add-friend-search").serialize(),
function(data){
$("#insert-activity").html(data);
});
$("#add-friend-search").slideUp("slow",function(){});
}); //end click
You cant call your view directly, and you don't need to. The post should return the data, which you can write out to your #insert-activity
element.
你不能直接打电话给你的观点,你不需要。帖子应该返回数据,您可以将其写入#insert-activity元素。