我试图在ajax调用后显示数据,但显示后它消失了
这是我的代码:
<script src="js/jquery.js"></script>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
$(document).ready(function(){
$(".medicine").keyup(function(){
var txt=$(this).val();
$.post("search.php",{medicine:txt},function(result){
$("#search-result").html(result);
});
});
$(document).on('click','#find', function () {
var input = $("#text").val();
var url = 'row.php';
var data = input;
$.ajax({
type: "POST",
url: url,
data: {data:data},
success: function (data) {
$(document).find('table').remove();
$("#temp_table").html(data);
}
});
});
});
</script>
第一个功能用于搜索栏,该功能正在工作,第二个功能也可以工作,但是当数据进入成功功能时,它会在临时 div 中显示一秒钟并消失
最佳答案
当你的ajax完成时,success
回调函数删除所有 <table>
使用 .remove()
引起的元素功能。
$(document).find('table').remove();
<小时/>Description: Remove the set of matched elements from the DOM.
如果您想清除<table>
的html内容元素而不是删除它们(我的猜测),请使用 .empty()
相反
$.ajax({
type: "POST",
url: url,
data: {
data: data
},
success: function(data) {
$('table').empty();
$("#temp_table").html(data);
}
});
关于javascript - ajax调用后表消失了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29577417/