[英]Removing contents of existing div not working
I have a function that gets data back from php and if it receives "unauthorized", it's supposed to show a modal explaining the possible error AND remove any content from the div. 我有一个从php取回数据的函数,如果它收到“未经授权”的信息,则应该显示一个模态解释可能的错误并从div中删除任何内容。 It basically does this, but the code still remains, so someone could just look at the source and read what's there.
它基本上是这样做的,但是代码仍然存在,因此有人可以只看源代码并阅读其中的内容。
#main_content
starts out as display:hidden
, so I wouldn't think it would appear at all with the code I have. #main_content
开始时是display:hidden
,所以我认为它不会随我拥有的代码一起出现。
function callCharts() {
$.ajax({
url: 'all_data.php',
type: 'GET',
success: function(data) {
var check = data;
if (check =='unauthorized') {
$('#main_content').remove();
// also have tried .empty and .html("")
$('#unauthorized_modal').modal('show');
}
else {
$('#main_content').css("display","inherit");
console.log("authorized");
}
}
});
}
Relevant HTML 相关HTML
<div id="main_content" style="display:none;">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<div class="block-flat" style="margin-bottom:10px; ">
<div class="header">
<h3 style="display:inline;">Data Overview</h3>
</div>
</div>
</div>
</div>
</div>
You need to put your ajax function within this 您需要将ajax函数放入其中
$( document ).ready(function() {
callCharts();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.