[英]Pass PHP variable using jQuery html() function to div
我试图使用PHP和jQuery从MySQL数据库中获取拼贴的部分。
我正在获取数据正常,但是当我使用html()
将结果添加到div
时,我收到错误
这是我的代码:
$("#collage_id").on('change',function(e){
$("#sections").fadeOut(1200);
if(this.value==0){
$("#sections").fadeOut(1200);
}
else {
<?PHP
$collage_sections=new DataBase();
$sections=$collage_sections->get_sections();
$sections_checkbox="";
while($section=mysqli_fetch_array($sections)){
$sections_checkbox.="<label class='checkbox-inline'><input type='checkbox' value='$section[0]'>$section[1]</label>";
}
?>
$("#sections").html(<?PHP echo $sections_checkbox; ?>).fadeIn(1200);
}
});
有没有人有任何帮助或想法?
正如@Swellar所说,将$sections_checkbox
变量包装在引号中。 目前,javascript将其视为变量,而不是您想要的字符串。 作为提示,请始终在浏览器中使用控制台。 您将找到大多数语法错误的答案。 要修复错误,请执行此操作。
$("#sections").html("<?php echo $sections_checkbox; ?>").fadeIn(1200);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.