【发布时间】:2014-09-06 14:33:29
【问题描述】:
我想进行搜索,但我得到重复的结果,如何从 prev ajax 请求中删除 prev 代码我在 ajax 中的代码是:
<script>
$(function () {
$("#sample_search").keyup(function () {
var that = this,
value = $(this).val();
$.ajax({
type: "post",
url: "<?php echo site_url('home/search')?>",
data: {
'search_keyword' : value
},
dataType: "text",
success: function(msg){
//we need to check if the value is the same
$("#prostor").append("<p id='rezultati'>"+msg+"</p>");
}
});
});
});
</script>
在php中
public function search(){
if(isset($_post['search_keyword'])){
$var = $_post['search_keyword'];
$q = $this->db->query("SELECT * from users where username like '%{$var}%'");
foreach ($q ->result() as $a){
echo $a->username;
}
}
}
我的问题是如何删除上一个搜索结果
【问题讨论】:
-
“重复代码”你的意思是什么?请指定您需要的输出和当前输出。
-
我的意思是repatavive结果,例如如果我输入b然后我,我会得到billbill的结果
-
$_post['search_keyword'](small$_post) 为你工作吗? -
为了防止结果重复,请在您的 jquery 代码中使用
html()而不是append()。
标签: jquery ajax codeigniter search