简体   繁体   English

如何从 PHP 中保存 Javascript 变量信息

[英]How to save in a Javascript variable information from PHP

I want to do a page were a user can connect with a teacher in order to ask a question from a subject.我想做一个页面,用户可以与老师联系以便从主题中提问。 The thing is that II´ve been searching the web but I couldn´t find a way to store in a JavaScript variabl (var name = .....) information that I have recieved from PHP ($.get( "LINK PHP",function( data ) {}).问题是我一直在网上搜索,但我找不到一种方法来存储我从 PHP ($.get("LINK PHP ",function( 数据 ) {})。

Thanks in advance.提前致谢。

 $.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>

Write the javascript out using php... Something like this... been a while since I did php but remember php is server side and js happens after the page is rendered, in this use case.使用 php 写出 javascript ......像这样的事情......自从我使用 php 以来已经有一段时间了,但记住 php 是服务器端,而 js 在页面呈现后发生,在这个用例中。

 <script type='text/javascript'>
        <?php 
          echo "let professorId ='".$profId."'";
        ?>
    </script> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM