我想做一个页面,用户可以与老师联系以便向某个学科提出问题。问题是II一直在网上搜索,但是我找不到在JavaScript variabl(变量名= .....)中存储从PHP($ .get(“ LINK PHP “,function(data){})。
先谢谢了。
$.get("LINK PHP", function(data) {
var divProfesores = $('#profesores');
for (var profesor of data) {
var ficha_profesor = `<div id="products" class="row list-group"><div class="item col-xs-4 col-lg-4"><div class="thumbnail"><img class="group list-group-image" src="../IMAGENES/logo final.png" alt="" /><div class="caption"><h4 class="group inner list-group-item-heading">${info_profesor}</h4><p id="nom">${profesor.nombre}</p><p id="tel">${profesor.telefono}</p><p class="group inner list-group-item-text">${profesor.descripcion}</p><div class="row"><div class="col-xs-12 col-md-6"><p class="lead"></p></div><div id="con"><button class="btn waves-effect waves-light#80cbc4 teal lighten-3" type="button" onclick="conectar('${profesor.id}')">Conectar</button></div></div></div></div></div>`
divProfesores.append(ficha_profesor)
}
});
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="products" class="row list-group">
<div class="item col-xs-4 col-lg-4">
<div class="thumbnail">
<img class="group list-group-image" src="../IMAGENES/logofinal.png" alt="" />
<div class="caption">
<h4 class="group inner list-group-item-heading">
Teacher basic Info:</h4>
<div id="infoprof">
</div>
<div class="row">
<div class="col-xs-12 col-md-6">
<p class="lead">
</p>
</div>
<div id="con">
<button class="btn waves-effect waves-light#80cbc4 teal lighten-3" id="id" type="button">Conect with Teacher</button>
</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
使用php编写javascript ...类似的东西...已经有一段时间了,因为我使用过php,但请记住php是服务器端,并且在此用例呈现页面后便发生了js。
<script type='text/javascript'>
<?php
echo "let professorId ='".$profId."'";
?>
</script>