PHP调用JS问题

代码-君 2015-11-05 08:51:13
<script type="text/javascript">
function show(){
document.form01.style.display="";
}
</script>
<?php
require_once 'include.php';
//checkLogined(); //检测是否登陆
if(@$_SESSION['username']==""){
//echo "<script>alert('没有登陆,请先登陆')</script>";
echo "<script>show()</script>";
}

$pid = $_REQUEST['pid']; //获取传过来的商品ID
$sql = "select * from bargaining_pro where pId={$pid}"; //根据商品ID查询出商品
$rows=fetchAll($sql); //得到每条数据
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>活动主页</title>
</head>
<body>
<h3>项目详情</h3>
<?php foreach ($rows as $row):?>
<p><?php echo $row['pName'];?></p>
<p>项目描述</p>
<img width="10%" src="admin/uploads/<?php echo $row['pImage'];?>"/>
<a href="doAction.php?act=bargain&pid=<?php echo $row['pId'];?>&userid=<?php echo $_REQUEST['userid'];?>">砍一刀</a><!-- 商品ID和登陆用户ID -->
<p>砍掉0元</p>
<a href="#">分享朋友</a>
<?php endforeach;?>
<form method="post" name="form01" action="#">
<label>用户名:<input type="text" name="username" id="username"/></label>
<label>电话:<input type="tel" name="tel" id="tel"/></label>
<button id="sub">提交</button>
</form>
<script type="text/javascript">
window.onload = function(){
document.form01.style.display="none";
}

document.getElementById("sub").onclick = function(){
var request = new XMLHttpRequest();
request.open("POST","<?php echo $_SERVER['PHP_SELF']?>");
var name = document.getElementById("username").value;
var tel = document.getElementById("tel").value;
if(name=="" && tel==""){
alert("输入框不能为空");
return false;
}
var data = "username="+name+"&tel="+tel;
request.send(data);
request.onreadystatechange = function(){
if(request.readyState === 4){
if(request.status===200){
alert("登录成功");
}
}else{
alert("登录失败");
}
}
}
</script>
</body>
</html>

当session为空的时候 调用show()函数 让表单显示出来 这么写没反应 正确的应该怎么写的
...全文
128 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2015-11-06
  • 打赏
  • 举报
回复
没有看到 session_start();

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧