gpt4 book ai didi

php - JQUERY - .html() 也可以查看php

转载 作者:行者123 更新时间:2023-11-30 08:59:27 27 4
gpt4 key购买 nike

以下脚本使用ajax发送数据进行登录

我想通过本质上使用 session 变量 ($ _SESSION) 来格式化返回的数据

我能行

 $("#login").click(function(){

username=$("#user_name").val();
password=$("#password").val();
$.ajax({
type: "POST",
url: "inc/login.inc.php",
data: "username="+username+"&password="+password,
success: function(msg){
if(msg!='false')
{
$("#login_form").fadeOut("normal");
$("#shadow").fadeOut();
$("#profile").html("<\?php print(\"$_SESSION['name'].\" <a href='inc\/logout.inc.php' id='logout'>Logout k2<\/a>\");\?>");
//valori menù
if(tipo=='1')
{$("#admin").css('display','none')}

}
else
{
$("#add_err").html("Username o password errata");
}
},
beforeSend:function()
{
$("#add_err").html("<img hspace='84' src='img/loading.gif' alt='Loading...' width='32' height='32'>" )
}
});
return false;

});

特别是这是可能的,这种方式会打印刚刚登录的用户的名字。不然我都不知道怎么办了

$("#profile").html("<\?php print(\"$_SESSION['name'].\" <a href='inc\/logout.inc.php' id='logout'>Logout k2<\/a>\");\?>");

最佳答案

在脚本已经被处理后,您不能插入 PHP 代码。

要么通过 ajax 将其拉入,要么将实际的 PHP 输出包含到您的 javascript 中。

即,在 page.php 中

   <script>
var sessionName = '<?php echo $_SESSION['name']; ?>';
</script>

以后需要的时候再用

 $("#profile").html(sessionName + " <a href=\"inc/logout.inc.php\" id=\"logout\">Logout k2</a>");

关于php - JQUERY - .html() 也可以查看php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10555349/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com