我想进行搜索,但得到重复的结果,如何从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;
}
}
}
我的问题是如何删除上一个搜索结果
使用html()
的,而不是append()
在$.ajax
打电话,像下面
success: function(msg){
//we need to check if the value is the same
$("#prostor p#rezultati").html(msg);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句