我正在尝试使用JS在登录时将用户定向到其个人资料页面。我需要在网址中获取个人资料ID,但无法正常工作。
if(data == 'success'){
window.location = 'profile.php?id=<?= $user_id ?>';
} else {
$('#signin_errors').html(data);
}
有什么建议吗?
最佳答案
如果这是<script src="blah.js"></script>
中包含的文件,请将其更改为<script src="blah.php"></script>
并将此代码粘贴在blah.php
中
<?php header("Content-type: application/x-javascript");
$user_id = "whatever"; ?>
if(data == 'success'){
window.location = 'profile.php?id=<?php echo $user_id ?>';
} else {
$('#signin_errors').html(data);
}